Bezier Curves

# Bezier Curves

Once, the F117a stealth bomber was made of flat panels, now the Blackbird is a curved beautiful aircraft. Once, concept sports cars were designed with straight edges, now you see elegantly organic vehicles on the road. Until now, you may have only been able to draw straight lines on your computer, Breshenhan or anti-aliased, but soon you will be able to bend them.

 Lines Curves In the past, you have probably specified a line by the position of it's end points. The Breshenham or anti-aliased algorithm simply draws a straight line between the two points. A bezier curve allows you to specify, not only the end points of the line, but also the direction of the line as it passes through the end points. The algorithm draws a curve that passes through the end points at an angle parallel to the specified direction.

 All sorts of curves can be specified with different direction vectors at the end points. Reflex curves appear when you set the vectors in different directions. You can even make loops.

Drawing the Curve:

A look back on drawing a line:
Drawing a line is a matter of starting at one end point, and moving directly towards the other end point, drawing as you go. This is also known as linear interpolation.

 Linear Interpolation ``` procedure draw_line(point1, point2) loop t from 0 to 1 in steps of .01 a = t b = 1 - t point = (point1 * b) + (point2 * a) drawpixel (point) end of loop end of draw_line ```

Drawing the curve:
To draw a curve, we shall move from linear interpolation, to cubic interpolation.

We choose two end points, and call them A and D.
Next we choose two direction vectors for those end points, and call them v1 and v2.
At the ends of those vectors, we shall define two new points:

B = A + v1
C = D + v2

With these four points defined, we can now use a cubic interpolation to draw a curve:
 Cubic Interpolation ``` procedure draw_bezier(A, v1, v2, D) B = A + v1 C = D + v2 loop t from 0 to 1 in steps of .01 a = t b = 1 - t point = A*b3 + 3*B*b2*a + 3C*b*a2 + D*a3 drawpixel (point) end of loop end of draw_bezier ```