Created
June 26, 2017 23:11
-
-
Save daneden/4170843a523240a3cb201556d9ad2de3 to your computer and use it in GitHub Desktop.
This file contains 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
// chaikin takes an array of points Pn and calculates points QRn | |
// [PVector] -> [PVector] | |
ArrayList<PVector> chaikin(ArrayList<PVector> P) { | |
ArrayList<PVector> CP = new ArrayList<PVector>(); | |
for(int i = 0; i < P.size() - 1; i++) { | |
PVector p = P.get(i); | |
PVector p2 = P.get(i + 1); | |
float qx = lerp(p.x, p2.x, .25); // lerp() == linear interpolation between 2 values at point T where 0 <= T <= 1 | |
float rx = lerp(p.x, p2.x, .75); | |
float qy = lerp(p.y, p2.y, .25); | |
float ry = lerp(p.y, p2.y, .75); | |
PVector q = new PVector(qx, qy); | |
PVector r = new PVector(rx, ry); | |
CP.add(q); // essentially Array.push(q) | |
CP.add(r); | |
} | |
return CP; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment