Here's a some information on Bezier Curves. Although I've used them for 12 years I never understood the math before. I learned this today and would like to make it simple for others.
Bezier (Bézier) math is an easy way to describe a curve between two points. Instead of having a two points with many individual points in between to describe a curve, you can have just two additional control points and be more accurate.
There are a few things you need to know about Bezier Curves.
1) You need 4 points in total for a typical bezier curve. They are:
Start Point (X0,Y0)
Control Point 1 (X1,Y1)
Control Point 2 (X2,Y2)
End Point (X3,Y3)
2) To find a point along the curve you will need to perform a two step calculation. The second calculation is based partly on the first so you need to do it in order.
First Set of Calculations:
cx = 3*(X1-X0)
bx = 3*(X2-X1)-cx
ax = X3-X0-Cx-Bx
cy = 3*(Y1 - Y0)
by = 3*(Y2 - Y1)-cy
ay = Y3-Y0-Cy-By
Second Set of Calculations:
Since you want to find a point along the curve you will need to figure out how far along the curve that point is in a decimal percentage. If 0 is the starting point and 1 is the ending point the curve lies inbetween 0 and 1. "t" will be the determining percentage value along the curve. For example to find a curve point at the 50% mark you set "t" to equal ".5"
X(t) = ax*t^3 + bx*t^2 + cx*t + X0
Y(t) = ay*t^3 + by*t^2 + cy*t + Y0
(Note that the "^" means "to the power" or how many times a number is multiplied by itself.)
-----------------------------------------------------
Ok here's an example of one point in a bezier curve. I could post a snippet later to draw this curve although there are other ones already here.
Starting Point:
X0=1
Y0=1
Control Point 1:
X1=3
Y1=5
Control Point 2:
X2=10
Y2=4
End Point:
X3=11
Y3=8
Step 1:
cx = 3*(3-1) (equals 6)
bx = 3*(10-3)-6 (equals 15)
ax = 11-1-6-15 (equals -11)
cy = 3*(5-1) (equals 12)
by = 3*(4-5)-12 (equals -15)
ay = 8-1-12-(-15) (equals 10)
Step 2:
Find the point half way (.5)
X = -11*.5^3 + 15*.5^2 + 6*t + 1 (Equals 6.375)
Y = 10*.5^3 + (-15)*.5^2 + 12*.5 + 1 (Equals 4.5)
Final answer X=6.375, Y=4.5
If you wanted to plot the whole curve you could use a "for next" statement and use the incrementing variable as your "t" value and step it through a small value like .02 (5o steps total etc.)
Good luck!
More info:
http://www.moshplant.com/direct-or/bezier/math.html
1/6/09 - updated this post as the word Bezier had become "Bézier" during a forum transition.
Wannabe Game Designer. Wannabe Programmer. Expert Dreamer.
Long Island Amateur Game Development Group http://www.meetup.com/LIAGDG/