0
votes

User is supposed to enter N number of control points, by which first Bezier curve is plot. After this, the user again enters P number of control points, and then using the last point of the first curve and the recently entered control points, another Bezier curve is blended with it, which has to be continuous with the first curve. I am using the following to plot curves, but unable to check for continuity. Please help.

N=input('enter the number of control points ');
for (i=1:N)
    P(i,:)=input('enter the coordinates of point [x y]' );
end

K=input('enter the number of points to plot ');
syms u
Px=0;
Py=0;

for(i=1:N)
    b=(factorial(N-1)/factorial(N-1-i+1)/factorial(i-1))*(u^(i-1))*(1-u)^(N-1-i+1);
    Px= Px+ b*P(i,1);
    Py= Py+ b*P(i,2);
end

for(i=1:K+1)
    Rx(i)=subs(Px,u,(i-1)/K);
    Ry(i)=subs(Py,u,(i-1)/K);
end
plot(Rx,Ry)
axis equal
1

1 Answers

1
votes

Let me assume the first set of points are Q(0), Q(1),...Q(N-1) and the 2nd set of points are R(0), R(1),..., R(P-1) for easier discussion next. Since the two Bezier curves already share the same point Q(N-1) as control point, they will be G0 continuous. If you want the two Bezier curves to have C1 or even C2 continuity, then you need to enforce certain relationship between the control points of these two Bezier curves. For achieving C1 continuity, you need to make sure

Q(N-1) - Q(N-2) = R(0) - Q(N-1)

For achieving C2 continuity, you also need to make sure

Q(N-1) - 2*Q(N-2) + Q(N-3) = R(1) - 2*R(0) + Q(N-1)

Please note that above equations are for enforcing C1/C2 continuity. For two Bezier curves to look "smoothly-connected", you only need to enforce G1/G2 continuity, which is not as restrict as C1/C2 continuity but are slightly harder to compute. For example, you only need to make sure Q(N-1), Q(N-2) and R(0) are collinear for enforcing G1 continuity.

BTW, in your posted matlab codes, you used factorial() for evaluating points on Bezier curve. This is not recommended as factorial(N) could become a very big number with higher degree Bezier curves. You should use de Castejlau algorithm instead.