The Bezier Curve is one of the most used parametric curves. It is used extensively in computer graphics and computer aided design(CAD). The cubic curve can be defined by four points. An algorithm to draw the curve involves multiple linear interpolations using [i]t[/i] as a parameter that goes from zero to one.[br]Step 1: Linearly interpolate between each successive pair of points based on [i]t[/i].[br][br][list][*][i]P[/i][sub]AB[/sub][i] = (1-t) P[/i][sub]A[/sub][i] + t P[/i][sub]B[/sub][/*][*][i]P[/i][sub]BC[/sub][i] = (1-t) P[/i][sub]B[/sub][i] + t P[/i][sub]C[/sub][/*][*][i]P[/i][sub]CD[/sub][i] = (1-t) P[/i][sub]C[/sub][i] + t P[/i][sub]D[/sub][/*][/list]Here [i]P[/i] represents the point coordinates [i]P[/i][sub]A[/sub] = ([i]Ax[/i], [i]Ay[/i]) which results in two equations. One for [i]x[/i] and one for [i]y [/i]and in three dimensions there would be an additional equation for [i]z[/i]. [list][*][i]AB[sub]x[/sub] = (1-t) A[sub]x[/sub][/i][i] + t B[sub]x[/sub][/i][/*][/list][list][*][i]AB[sub]y[/sub] = (1-t) A[sub]y[/sub][/i][i] + t B[sub]y[/sub][/i][/*][/list][br]Step 2: Linearly interpolate between each successive pair of the new points[br][list][*][i]P[/i][sub]ABC[/sub][i] = (1-t) P[/i][sub]AB[/sub][i] + t P[/i][sub]BC[/sub][/*][/list][list][*][i]P[/i][sub]BCD[/sub][i] = (1-t) P[/i][sub]BC[/sub][i] + t P[/i][sub]CD[/sub][/*][/list][br]Step 3: Linearly interpolate between each successive pair of the new points[br][list][*][i]T = (1-t) P[/i][sub]ABC[/sub][i] + t P[/i][sub]BCD[/sub][/*][/list][br]These steps can be algebraically combined to give the coordinates as a cubic polynomial function of [i]t.[br][br]T[sub]x[/sub] = (1-t)[sup]3[/sup] A[sub]x[/sub] + 3 (1-t)[sup]2[/sup] t B[sub]x[/sub] + 3 (1-t) t[sup]2[/sup] C[sub]x[/sub] + t[sup]3[/sup] D[sub]x[/sub] [br][i]T[sub]y[/sub] = (1-t)[sup]3[/sup] A[sub]y[/sub] + 3 (1-t)[sup]2[/sup] t B[sub]y[/sub] + 3 (1-t) t[sup]2[/sup] C[sub]y[/sub] + t[sup]3[/sup] D[sub]y[/sub] [/i][/i]
The applet shows two graphs. The left pane shows the [i]x[/i] and [i]y[/i] coordinates while the right pane shows the [i]x[/i] and [i]y[/i] values with respect to the [i]t[/i] parameter. The left pane shows four control points that can be moved, several check boxes and a slider for the [i]t[/i] value.[br][br]The check boxes functions [br][list][*]Show Point : Shows the point at the [i]t[/i] value of the slider[/*][*]Animate : Starts incrementally increasing the [i]t[/i] value. Used in conjunction with Show Trace will draw points along the curve.[/*][*]Show Trace : Draws points as the slider is moved, keeping all points[/*][*]Show Path : Draws the Bezier curve for the control points[br][/*][*]Show Lines : Draws the lines connecting the control points and lines connecting the intermediate interpolated points.[/*][/list]
[list=1][*]Turn on animation and watch how the plus point moves from [i]A[/i] to [i]B[/i]. Also watch on the right graph window how the [i]x[/i] and [i]y[/i] values change with [i]t[/i].[/*][*]Turn on show trace to see the curve traced out. Watch both graphs.[/*][*]Stop animation and turn on show lines. This shows all of the linear interpolation points on lines. Move the [i]t[/i] slider to see how the points and lines move.[/*][*]Turn the trace off and show the path.[/*][*]Move the control points and observe how the curve changes.[/*][*]Try to make the curve into[/*][/list][list][*]Sine wave[/*][*]A ribbon[/*][*]A circle[/*][*]A Vee[/*][/list]
The usefulness of a Bezier Curve is how it can be easily manipulated. Transforming (translation, scaling, rotation, reflection) the control points transforms the curve in the same way.[br]Another property is that the curve is always inside a convex hull formed by the control points. This is useful because a bounding box can be defined where the curve is inside the box. Knowing the curve is inside an area is very helpful for looking at interactions and intersections.[br]A simple method for finding a bounding box is to rotate all the control points so that the line from [i]A[/i] to [i]D[/i] aligns with the [i]x[/i] axis. Then taking the minimum and maximum values of the control point coordinates defines a box in the rotated frame that contains the curve. Rotating this box back to the original orientation then defines a bounding box. The Show Bounding Box in the below applet will show this box.
A related property is that the curve can be easily split into two curves. Turn on show lines and move the [i]t[/i] slider to about the middle. The curve can be split into two curves by using the intermediate points. The curve defined by the control points A, AB, ABC, and T will define one curve and the control points T, BCD, CD, and D define another curve. Show Split will highlight the first curve.[br]With both Show Bounding Box and Show Split selected the bounding box for the split curve is shown. Notice that as the curve gets shorter by moving [i]t[/i] toward zero the bounding box approaches a line. This is one of the reasons Bezier Curves are use so much in Computer Graphics. A computer can draw a straight line easily so a curve can be split until the bounding box gets close enough to use a straight line to represent a piece of the curve.