Java Reference
In-Depth Information
How It Works
This time we create all the shapes first and then draw them. The two arcs are segments of ellipses of the
same height and width. The lower segment is shifted up with respect to the first so that they intersect,
and the distance between the top of the rectangle for the first and the bottom of the rectangle for the
second is diameter , which is the diameter of the first circle we create.
Both circles are created centered between the two arcs and are concentric. Finally we draw all the
shapes - the arcs in black and the circles in blue.
Next time we change the code in Sketcher, we will be building the application as it should be, so
remove the temporary code from the paint() method and the code that sets the background color in
the ColorAction inner class to the SketchFrame class.
Curves
There are two classes that define arbitrary curves, one defining a quadratic or second order curve and
the other defining a cubic curve. The cubic curve just happens to be a Bézier curve (so called because it
was developed by a Frenchman, Monsieur P. Bézier, and first applied in the context of defining
contours for programming numerically-controlled machine tools). The classes defining these curves are:
Class
Description
QuadCurve2D
This is the abstract base class for the QuadCurve2D.Double and
QuadCurve2D.Float classes that define a quadratic curve segment.
The curve is defined by its end points plus a control point that defines the
tangent at each end. The tangents are the lines from the end points to the
control point.
CubicCurve2D
This is the abstract base class for the CubicCurve2D.Double and
CubicCurve2D.Float classes that define a cubic curve segment. The
curve is defined by its end points plus two control points that define the
tangent at each end. The tangents are the lines from the end points to the
corresponding control point.
In general, there are many other methods for modeling arbitrary curves, but the two defined in Java
have the merit that they are both easy to understand, and the effect on the curve segment when the
control point is moved is quite intuitive.
Search WWH ::




Custom Search