Sign in to follow this  
Quak

Rendering n-degree bezier splines

Recommended Posts

Quak    206
Hi, i want to render a 2d bezier spline with an abitrary degree. This is the function i have written but it doesn't work like expected because pixels are drawn outside the screen. If i just render the lines from point p0 to pn it works ( n = degree ). B is the bernstein polynomial.
void CBezierSpline::Render( void ) const
{
        //rendering control lines
	for ( int i=0; i<degree; i++ )
	{
		DrawLine32( (&p0)[i], (&p0)[i+1], grey ); 
	}

	float B, t;
	vector2 pt0, pt1;

	t = 0.1f;
	pt0 = p0;

	for ( int j=0; j < 10; j++ )
	{
                pt1 = vec2_origin; //FIXED: added this line

		for ( int k=0; k<=degree; k++ )
		{
                        //compute the polynomial where k is the index to the control point and t€[0,1]
			B = maths::nueki( degree, k ) * powf( t, k ) * powf( 1.0f - t, degree - k );
			pt1 += (&p0)[k] * B;
		}

		DrawLine32( pt0, pt1, color );

		pt0 = pt1;
                //render the curve with fixed steps of 0.1
		t += 0.1f;
	}
}
 





Can you find a mistake in my function ? thank you for your help Quak EDIT: I found the mistake and corrected the code above. [Edited by - Quak on June 10, 2005 3:54:34 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this