Java Reference
In-Depth Information
The argument to the constructor is the control point that is to be marked. The constructor stores this
control point in the member
center
and creates an
Ellipse2D.Double
object that is the circle to mark
the control point. The class also has a method,
draw()
, to draw the marker using the
Graphics2D
ob-
ject reference that is passed to it, so
Marker
objects can draw themselves, given a graphics context.
The
getCenter()
method returns the center of the marker as a
Point2D.Double
reference. You use the
getCenter()
method when you draw tangent lines from the end points of a curve to the corresponding
control points.
You can now add fields to the
CurveApplet
class to define the
Marker
objects for the control points.
These definitions should follow the members that define the points:
// Markers for control points
private Marker ctrlQuad = new Marker(control);
private Marker ctrlCubic1 = new Marker(controlStart);
private Marker ctrlCubic2 = new Marker(controlEnd);
Directory "CurveApplet 2 displaying control points"
You can now add code to the
paint()
method for the
CurvePane
class to draw the markers and the tan-
gents from the end points of the curve segments:
@Override
public void paint(Graphics g) {
// Code to draw curves as before...
// Create and draw the markers showing the control points
g2D.setPaint(Color.red);
// Set the color
ctrlQuad.draw(g2D);
ctrlCubic1.draw(g2D);
ctrlCubic2.draw(g2D);
// Draw tangents from the curve end points to the control
marker centers
Line2D.Double tangent = new Line2D.Double(startQ,
ctrlQuad.getCenter());
g2D.draw(tangent);
tangent = new Line2D.Double(endQ, ctrlQuad.getCenter());
g2D.draw(tangent);
tangent = new Line2D.Double(startC, ctrlCubic1.getCenter());
g2D.draw(tangent);
tangent = new Line2D.Double(endC, ctrlCubic2.getCenter());
g2D.draw(tangent);
}