## Homework 6, due Wednesday, Oct 29.

Please note: I've added one more small but required task for this assignment (see below in green).

Splines:

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:

• When the user clicks at a pixel (x,y) in the applet window, the applet should add a control point at that pixel. The first control point you add is control point 0.

Every third control point (ie: control points 3, 6, 9, etc.) completes a Bezier curve.

• When the user drags on an existing control point (ie: does a mouseDown event very close to that control point, followed by a sequence of mouseDrag events), the applet should move that control point, so that it follows the cursor position.

• Between successive control points, draw a faint line (say, a gray or pink or light blue color).

• Mark control points 0,3,6 ... 3n ... with large dots (you can use the `g.fillOval` method for this) to show that those control points are the ones which mark the beginning and end of the individual Bezier curves.

• Plot the individual Bezier curves defined by points (0,1,2,3), (3,4,5,6), (6,7,8,9), etc., as described below.

• Create a picture of something cool out of Bezier curves. You might want to create an interesting cartoon character, or some sort of fancy letter shape, or perhaps a halloween theme of some sort. Remember that you can also use different colors to make things more interesting. If you're feeling a little ambitious, you can try to create filled-in Polygons, rather than just using the `drawLine` method. 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 we covered in class, the way you define a Bezier curve from four control points A,B,C,D is to treat the set of x coordinates {Ax, Bx, Cx, Dx} and the set of y coordinates {Ay, By, Cy, Dy} independently.

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:

 -1 3 -3 1 3 -6 3 0 -3 3 0 0 1 0 0 0

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:

 Ax Bx Cx Dx Ay By Cy Dy
into the two column vectors of cubic coefficients:
 ax bx cx dx ay by cy dy

which will let you evaluate the cubic polynomials:

X(t) = axt3 + bxt2 + cxt + dx
Y(t) = ayt3 + byt2 + cyt + dy

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 methods `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:

• When the user moves one of the interpolating knots: 0,3,6, etc., then you should move the two knots before and after it (knots 3n-1 and 3n+1) by the same amount;

• When the user moves one of the non-interpolating key points, then you should move the key point on the other side of the nearest non-interpolating key point so that the three successive key points 3n-1,3n,3n+1 remain co-linear.

You can try to make interesting content, such as specifying alphabetic letters.