It’s relatively straightforward interpolating a single bezier curve. What I’m looking for is a way to interpolate a continuous bezier curve. I’m assuming it’s possible, and if I wasn’t pressed for time I’d probably figure it out eventually. But I seek the help of the experts here so I can take a shortcut given my production demands.
So the question is: Given a continuous bezier comprised of an arbitrary number of bezier segments how does one normalize the entire curve to grab an arbitrary interpolated point on it?
Here’s a little test case using arbitrary anchor and control points. Ideally the interp()
method will evaluate the entire curve, not just the first bezier segment.
void setup(){
size(400, 400,P3D);
background(255);
myBez mb = new myBez();
shape(mb.ps);
mb.interp(20);
}
class myBez{
PShape ps;
PVector apt1 = new PVector(100, 100);
PVector cpt1 = new PVector(-100, 220);
PVector apt2 = new PVector(200, 100);
PVector cpt2 = new PVector(200, 100);
PVector apt3 = new PVector(150, 200);
PVector cpt3 = new PVector(250, 100);
myBez(){
ps = createShape();
ps.beginShape();
ps.strokeWeight(3);
ps.vertex(apt1.x, apt1.y);
ps.bezierVertex(cpt1.x, cpt1.y, cpt2.x, cpt2.y, apt2.x, apt2.y);
ps.bezierVertex(cpt2.x, cpt2.y, cpt3.x, cpt3.y, apt3.x, apt3.y);
ps.endShape();
}
void interp(int segs){
for (int i=0; i<=segs; i++){
float t = i / float(segs);
float x = bezierPoint(apt1.x, cpt1.x, cpt2.x, apt2.x, t);
float y = bezierPoint(apt1.y, cpt1.y, cpt2.y, apt2.y, t);
ellipse(x, y, 10, 10);
}
}
}
I figure a PShape
object would be easier to evaluate a continuous curve since it’s a self-contained object. Unfortunately I don’t know a way to evaluate a point on the curve (using bezierVertex
) that doesn’t require arrays of points. (I guess that’s the crux of the problem, isn’t it?) This problem is compounded if the evaluation of the normalized curve isn’t linear (eg: t = pow(i/segs, .75)
), which to me would be highly desirable.
Any help appreciated. Thank you.