Created
July 12, 2010 16:08
-
-
Save nervoussystem/472649 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PVector[] subdivide(PVector[] curve) { | |
//we add a midpoint for each segment, so we get twice as many points | |
PVector newCurve[] = new PVector[curve.length*2]; | |
for(int i=0;i<curve.length;++i) { | |
PVector currPt = curve[i]; | |
PVector prevPt = curve[(i-1+curve.length)%curve.length]; | |
PVector nextPt = curve[(i+1)%curve.length]; | |
newCurve[2*i] = new PVector(); | |
newCurve[2*i].add(PVector.mult(prevPt,.125)); | |
newCurve[2*i].add(PVector.mult(currPt,.75)); | |
newCurve[2*i].add(PVector.mult(nextPt,.125)); | |
newCurve[2*i+1] = new PVector(); | |
newCurve[2*i+1].add(currPt); | |
newCurve[2*i+1].add(nextPt); | |
newCurve[2*i+1].mult(.5); | |
} | |
return newCurve; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment