In class I talked about parametric cubic splines, and briefly mentioned parametric bicubic surface patches. What I would like you to do for this assignment is to implement an interactive Java applet that allows the user to compose a Bezier spline curve by adding control points, and by dragging around control points. Your program should behave as follows:
Every third control point (ie: control points 3, 6, 9, etc.) completes a Bezier curve.
g.fillOvalmethod for this) to show that those control points are the ones which mark the beginning and end of the individual Bezier curves.
An important thing to keep in mind is that
if you want two successive Bezier curves
that share some key point
to join together without a sharp bend between them,
must make sure that
the slope from
to the next key point
is equal to
the slope from the previous key point
In that way
your drawing can contain shaded areas bounded
by smooth curves.
An important thing to keep in mind is that if you want two successive Bezier curves that share some key point Pn to join together without a sharp bend between them, then you must make sure that the slope from Pn to the next key point Pn+1 is equal to the slope from the previous key point Pn-1 to Pn.
As I said in class, for every type of spline there is a unique matrix that transforms the control point values to the (a,b,c,d) values of the cubic polynomial at3+bt2+ct+d.
For Bezier curves, the particular matrix to use is:
To get the cubic polynomial equation for the x coordinates and y coordinates, respectively, you need to use this matrix to transform the two geometry column vectors:
which will let you evaluate the cubic polynomials:
Once you know the cubic polynomials that define X(t) and Y(t)
for any individual Bezier curve,
the simplest way to draw the curve
is to loop through values of t, stepping from 0.0 to 1.0,
and draw short lines between successive values.
For example, if you have already defined
double X(double t) and
double Y(double t),
then you can use code structured something like:
for (double t = 0 ; t <= 1 ; t += ε) g.drawLine((int)X(t), (int)Y(t), (int)X(t+ε), (int)Y(t+ε));
Opportunities for extra credit:
You can constrain the key points so that successive spline segments have the same slope where they join. You do this as follows:
You can try to make interesting content, such as specifying alphabetic letters.