11-22-2007 08:00 PM
11-22-2007 10:32 PM
struct pointMany thx
{
float x;
float y;
};
// 4 points define the bezier-curve.. These are the points used
// for the example-images on this page.
point a = { 40, 100 };
point b = { 80, 20 };
point c = { 150, 180 };
point d = { 260, 100 };
// simple linear interpolation between two points
void lerp (point &dest, point &a, point &b, float t)
{
dest.x = a.x + (b.x-a.x)*t;
dest.y = a.y + (b.y-a.y)*t;
}
// evaluate a point on a bezier-curve. t goes from 0 to 1.0
void bezier (point &dest, float t)
{
point ab,bc,cd,abbc,bccd;
lerp (ab, a,b,t); // point between a and b (green)
lerp (bc, b,c,t); // point between b and c (green)
lerp (cd, c,d,t); // point between c and d (green)
lerp (abbc, ab,bc,t); // point between ab and bc (blue)
lerp (bccd, bc,cd,t); // point between bc and cd (blue)
lerp (dest, abbc,bccd,t); // point on the bezier-curve (black)
}
// small test program.. just prints the points
void main (void)
{
point p;
for ( int i=0; i<1000; i++ )
{
float t = (float)i/999.0;
bezier (p,t);
printf ("%f %f\n", p.x, p.y);
}
}
11-23-2007 02:41 AM
11-23-2007 12:32 PM - edited 11-23-2007 12:42 PM
11-26-2007 04:38 AM