## Homework 11, due Wednesday, Nov 20.

Introduction to Splines:

In class we covered cubic parametric splines, and touched briefly on bicubic parametric 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 adds another control point at that pixel.

• 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 as to follow 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.

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

• 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. For the x coordinates, transform the column vector [Ax Bx Cx Dx]T by the characteristic Bezier matrix
 -1 3 -3 1 3 -6 3 0 -3 3 0 0 1 0 0 0

The resulting column vector [a b c d]T then provides the coefficients for the cubic polynomial

X(t) = at3 + bt2 + ct + d

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, 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:

```   double dt = .01;
for (double t = 0 ; t <= 1 ; t += dt)
g.drawLine((int)X(t), (int)Y(t), (int)X(t+dt), (int)Y(t+dt));
```

Opportunities for extra credit:

As usual, there are lots of opportunities for extra credit in this assignment. 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 knots, then you should move the knot on the other side of the nearest non-interpolating knot so that the three successive knots 3n-1,3n,3n+1 remain co-linear.

You can do forms of spline specification other than Bezier (eg: Hermite, B-Spline, etc.) You can try to do something other than cubic splines (eg: fourth degree Bezier). You can try to make interesting content, such as specifying alphabetic letters. Over the next day or so I'm going to be posting a list of interesting opportunities for special credit, so watch this space.

Next week we are going to be focusing much more on bicubic spline surfaces.