Java Reference
In-Depth Information
public Marker(Point2D.Double control) {
center = control; // Save control point as circle center
// Create circle around control point
circle = new Ellipse2D.Double(control.x-radius, control.y-radius,
2.0*radius, 2.0*radius);
}
// Draw the marker
public void draw(Graphics2D g2D) {
g2D.draw(circle);
}
// Get center of marker - the control point position
Point2D.Double getCenter() {
return center;
}
Ellipse2D.Double circle; // Circle around control point
Point2D.Double center; // Circle center - the control point
static final double radius = 3; // Radius of circle
}
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 object reference that is passed to it. The getCenter() method returns the center of the
marker as a Point2D.Double reference. We will use this method when we draw tangent lines from
the end points of a curve to the corresponding control points.
We will add fields to the CurveApplet class to define the markers for the control points. These
definitions should follow the members that defines the points:
// Markers for control points
Marker ctrlQuad = new Marker(control);
Marker ctrlCubic1 = new Marker(controlStart);
Marker ctrlCubic2 = new Marker(controlEnd);
We can now add code to the paint() method for the CurvePane class to draw the markers and the
tangents from the endpoints of the curve segments:
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);
Search WWH ::




Custom Search