Splines:
In class I talked about parametric cubic splines, and briefly mentioned parametric bicubic surface patches. For this assignment I would like you to implement an interactive Java applet that shows its user some cool picture made out of spline curves, and allows the user to drag around control points to modify that picture.
For this assignment you'll want to go back
to using the java.awt.graphics
class
that you used earlier in the semester,
since you'll mostly be drawing
lines and circles -
you will be making curves by drawing
lots of little successive lines end to end.
Your program should behave as follows:
fillPolygon
method,
rather than just draw curves via the drawLine
method.
fillOval
method)
to show that those control points are the ones
which mark the beginning and end of the individual Bezier
cubic spline curves.
An important thing to keep in mind is that if you want two successive Bezier curves that share some key point P3n to join together without a sharp bend between them, then you must make sure that the slope from P3n to the next key point P3n+1 is equal to the slope from the previous key point P3n-1 to P3n. In order to constrain the key points so that successive spline segments maintain the same slope at their common point when the user drags control points around, you should do something like the following:
Helpful notes:
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 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.
As we showed in class, for Bezier curves this transformation matrix 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:
into the two column vectors of cubic coefficients:
Ax
Bx
Cx
DxAy
By
Cy
Dy
ax
bx
cx
dxay
by
cy
dywhich will let you evaluate the cubic polynomials:
X(t) = axt3 + bxt2 + cxt + dx
Y(t) = ayt3 + byt2 + cyt + dyOnce 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)
anddouble 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+ε));