Cubic Bezier curves

This topic is 3317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Here is the MATLAB code that I wrote to generate a cubic bezier curve given 4 control points. It doesn't interpolate between two endpoints. Can you tell what is wrong with it? --------------------- clc clear p0 = [ 0; 0 ]; p1 = [ 5; 10 ]; p2 = [ 10; 15 ]; p3 = [ 20; -10 ]; G = [ p0 p1 p2 p3 ]; B = [ 1 -3 3 -1; 0 3 -6 -3; 0 0 3 -3; 0 0 0 1 ]; i = 1; for t = 0:0.05:1 T(1,i) = 1; T(2,i) = t; T(3,i) = t^2; T(4,i) = t^3; i = i + 1; end curve = G*B*T; grid on hold on plot( curve(1,:), curve(2, :) ); plot( G(1,:), G(2,:), '--rs', 'MarkerSize', 10 ); hold off --------------------- <br/>

Share on other sites
Hi Dynx, I think you have an error in your B matrix(the coefficient for P1*t^3 should be +3, not -3). Try this
B = [ 1 -3 3 -1; 0 3 -6 3; 0 0 3 -3; 0 0 0 1 ];

Share on other sites
Yep that was it thanks.

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631774
• Total Posts
3002286
×