1
votes

I am using this piece of code to cauculate a cubic bezier curve for s in [0, 1]. I want to extend the curve base on its geometric continuity. I tried just set s other than [0, 1] but the result is not correct. Is there actually a possible algorithm for calculating bezier point ?

pb, pbh, peh, pe are vectors of cubic bezier's control points.

*pq = pb*powf(1-s, 3) + pbh*(3*s*(powf(1-s, 2))) + peh*(3*powf(s, 2)*(1-s)) + pe*powf(s,3);

http://imageshack.us/photo/my-images/217/37013437.jpg/

This is the image I got. The white curve is what I want to get. There are three white Bezier curves linked one to another. The center one is the curve based on my code. The extended curve (the whole white curve which approximately twice as long as the center one) is what I wanted. However, if I just build a Bezier curve with my code with s in range [-0.5, 1.5], I will get the green one, which does not even pass the two original control points.

For the handles of green line I used the following code, which also, works fine with s in [0, 1]. p123 is the new left handle in green, and p234 is the new right one.

p12 = (pbh-pb)*s+pb;
p23 = (peh-pbh)*s+pbh;
p34 = (pe-peh)*s+peh;

p123 = (p23-p12)*s+p12;
p234 = (p34-p23)*s+p23;

Thanks in advance

1
Can you show a picture of the curve you got, how it is wrong, and the curve you want?Ned Batchelder

1 Answers

1
votes

If you don't have any additional information, then the most reasonable kind of extension you can get is in fact the one you obtain by passing arguments s outside the [0,1] range. Obviously, a curve extended in this fashion will contain the original curve, so as your green curve doesn't do so, the computation of the control points must be flawed. I just added formulas for that computation to another answer; they should work for you as well.

In the three-segment white curve, the control points are not symmetric around the junctions. This means that the curve will continue to go in the same direction (as they are on a line), but will change speed (with s interpreted as time) quite suddenly. You cannot achieve that shape with a smooth continuation. So the method described above won't give you the white shape, and you won't be able to obtain that shape at all unless you provide some kind of further information.