CPSC170A Assignment 5
Bézier Curves

Extra Credit

Friday, March 8th by 5:00 PM

A Bézier curve is a method for representing curves popularized by the French engineer Pierre Bézier in the 1960's. Bézier used the curves in the design automobiles. The curves are still popular today in drawing and animation applications because they offer an intuitive control over curve shape. Bézier curves can also be approximated very easily using a recursive algorithm developed by another Frenchman, Paul de Casteljau. You are going to create a program that allows users to draw a Bézier curve.

Details

The program should display a window that adds small circles where ever the mouse is clicked. Each circle in the window is a control point for a Bézier curve. Each time a control point is added the display should redraw the Bézier curve to include the new control point. In order to draw a Bézier curve, you need to calculate a series of points on the curve. The program should use a recursive function that implements the de Casteljau algorithm to calculate a fixed number of evenly spaced points on the curve. Then, draw lines between each pair of consecutive points, to draw the curve. The program does not need to draw the control structure, just the control points and the curve. The de Casteljau algorithm can be expressed recursively using the following equations:

dC(⟨ p1⟩ , t) = p1
dC( ⟨ p1, p2, pn ⟩, t) = dC( ⟨ interp(p1, p2, t), interp(p2, p3, t), interp(pn-1, pn, t) ⟩ , t)

Where t is the parametric distance, interp finds the point at the specified parametric distance between two points, and the angle brackets, ⟨⟩ , specify a list of points.

Submission: Submit your code as a zip file with your name as the zip file name on the course Inquire site.

Additional Work

These will not earn you extra credit, but are pretty easy to code if you feel motivated to do them

Movable Control Points: Add the ability to modify a Bézier curve after it has been drawn by dragging its control points. When the user is dragging a control point, the Bézier curve should be redrawn every time the mouse drag call-back function is called.

Animate de Casteljau: Create an animation of the de Casteljau algorithm. The program should draw all of the control structures computed with the de Casteljau algorithm with repeatedly larger values for t from 0 up to 1 and back down to 0 repeatedly.