# Rendering n-degree bezier splines

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

## Recommended Posts

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), (&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]

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631722
• Total Posts
3001892
×