Skip to content

Instantly share code, notes, and snippets.

@daneden
Created June 26, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daneden/4170843a523240a3cb201556d9ad2de3 to your computer and use it in GitHub Desktop.
Save daneden/4170843a523240a3cb201556d9ad2de3 to your computer and use it in GitHub Desktop.
// 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