Jump to content
  • Advertisement
Sign in to follow this  
Dynx

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.

If you intended to correct an error in the post then please contact us.

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 --------------------- Image Hosted by ImageShack.us<br/>

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!