There are several types of bezier curves.
After examining this on wikipedia and seeing the 'classroom' formula there is actually a simpler solution when it comes to programming them.
If you notice a bezier curve with 3 control points is quite simple. Take arbitrary control points A and C and an arbitrary control point B. The curve is created by first finding a point between A and B and finding a point between B and C using linear interpolation. Now draw a line between those points and interpolate on it the same distance as you did to find the two intermediate points. You need some type of time delta here though in order to draw the final curve.
Code:
D3DXVECTOR2 A;
D3DXVECTOR2 B;
D3DXVECTOR2 C;
D3DXVECTOR2 betweenAB;
D3DXVECTOR2 betweenBC;
float lerp = 0.0f;
while (lerp <= 1.0f)
{
D3DXVec2Lerp(&betweenAB,A,B,lerp);
D3DXVec2Lerp(&betweenBC,B,C,lerp);
D3DXVec2Lerp(&curvePoint,&betweenAB,&betweenBC,lerp);
lerp += 0.2f;
}
A 1D linear interpolation is a simple function:
Code:
float lerp(float start,float end,float lerp)
{
return start + lerp * (end - start);
}
I used D3DX here because it has overloaded the various operators so they work on 2D, 3D, and 4D vectors.
The bezier curve will trace out over time as the line between the computed points at time T between A and B and B and C changes.
You can extend this to cubic bezier curves as well and pretty much any order of curve and it just requires more linear interpolations.
I have never tried the 'school room' equations for the curves in code so I have no data as to whether or not the tried and true formulas are slower or faster in code. I would venture to guess the series of linear interpolations would win in the end. I use this in one version of my camera system that computes a new 'control point' between two camera positions. I then use this to run the camera's path along the bezier curve created by the 3 points.
But as has been said already without time there are no Bezier curves. There is no way to trace a curve from A to B without time and in fact there is no way to trace a line from A to B without time. A line is a simple bilinear interpolation between A and B and a curve with 3 points is 3 bilinear interpolations along 3 lines using the same coefficient for interpolation.