CubicCurve2Dpublic abstract class CubicCurve2D extends Object implements Shape, CloneableThe Class CubicCurve2D is a Shape that represents a segment of a quadratic
(Bezier) curve. The curved segment is determined by four points: a start
point, an end point, and two control points. The control points give
information about the tangent and next derivative at the endpoints according
to the standard theory of Bezier curves. For more information on Bezier
curves, see this
article. |
Constructors Summary |
---|
protected CubicCurve2D()Instantiates a new 2-D cubic curve.
|
Methods Summary |
---|
public java.lang.Object | clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
| public boolean | contains(double px, double py)
return Crossing.isInsideEvenOdd(Crossing.crossShape(this, px, py));
| public boolean | contains(double rx, double ry, double rw, double rh)
int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
return cross != Crossing.CROSSING && Crossing.isInsideEvenOdd(cross);
| public boolean | contains(java.awt.geom.Point2D p)
return contains(p.getX(), p.getY());
| public boolean | contains(java.awt.geom.Rectangle2D r)
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
| public java.awt.Rectangle | getBounds()
return getBounds2D().getBounds();
| public abstract java.awt.geom.Point2D | getCtrlP1()Gets the second control point.
| public abstract java.awt.geom.Point2D | getCtrlP2()Gets the second control point.
| public abstract double | getCtrlX1()Gets the x coordinate of the first control point.
| public abstract double | getCtrlX2()Gets the x coordinate of the second control point.
| public abstract double | getCtrlY1()Gets the y coordinate of the first control point.
| public abstract double | getCtrlY2()Gets the y coordinate of the second control point.
| public double | getFlatness()Gets the flatness of this curve, where the flatness is the maximum
distance from the curves control points to the line segment connecting
the two points.
return getFlatness(getX1(), getY1(), getCtrlX1(), getCtrlY1(), getCtrlX2(), getCtrlY2(),
getX2(), getY2());
| public static double | getFlatness(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)Gets the flatness of the cubic curve segment defined by the specified
values.
return Math.sqrt(getFlatnessSq(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2));
| public static double | getFlatness(double[] coords, int offset)Gets the flatness of the cubic curve segment defined by the specified
values. The values are read in the same order as the arguments of the
method
{@link CubicCurve2D#getFlatness(double, double, double, double, double, double, double, double)}
.
return getFlatness(coords[offset + 0], coords[offset + 1], coords[offset + 2],
coords[offset + 3], coords[offset + 4], coords[offset + 5], coords[offset + 6],
coords[offset + 7]);
| public double | getFlatnessSq()Gets the square of the flatness of this curve, where the flatness is the
maximum distance from the curves control points to the line segment
connecting the two points.
return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(), getCtrlX2(), getCtrlY2(),
getX2(), getY2());
| public static double | getFlatnessSq(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)Gets the square of the flatness of the cubic curve segment defined by the
specified values.
return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx1, ctrly1), Line2D.ptSegDistSq(x1,
y1, x2, y2, ctrlx2, ctrly2));
| public static double | getFlatnessSq(double[] coords, int offset)Gets the square of the flatness of the cubic curve segment defined by the
specified values. The values are read in the same order as the arguments
of the method
{@link CubicCurve2D#getFlatnessSq(double, double, double, double, double, double, double, double)}
.
return getFlatnessSq(coords[offset + 0], coords[offset + 1], coords[offset + 2],
coords[offset + 3], coords[offset + 4], coords[offset + 5], coords[offset + 6],
coords[offset + 7]);
| public abstract java.awt.geom.Point2D | getP1()Gets the starting point.
| public abstract java.awt.geom.Point2D | getP2()Gets the end point.
| public java.awt.geom.PathIterator | getPathIterator(java.awt.geom.AffineTransform t)
return new Iterator(this, t);
| public java.awt.geom.PathIterator | getPathIterator(java.awt.geom.AffineTransform at, double flatness)
return new FlatteningPathIterator(getPathIterator(at), flatness);
| public abstract double | getX1()Gets the x coordinate of the starting point.
| public abstract double | getX2()Gets the x coordinate of the end point.
| public abstract double | getY1()Gets the y coordinate of the starting point.
| public abstract double | getY2()Gets the y coordinate of the end point.
| public boolean | intersects(double rx, double ry, double rw, double rh)
int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
return cross == Crossing.CROSSING || Crossing.isInsideEvenOdd(cross);
| public boolean | intersects(java.awt.geom.Rectangle2D r)
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
| public abstract void | setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)Sets the data of the curve.
| public void | setCurve(java.awt.geom.Point2D p1, java.awt.geom.Point2D cp1, java.awt.geom.Point2D cp2, java.awt.geom.Point2D p2)Sets the data of the curve as point objects.
setCurve(p1.getX(), p1.getY(), cp1.getX(), cp1.getY(), cp2.getX(), cp2.getY(), p2.getX(),
p2.getY());
| public void | setCurve(double[] coords, int offset)Sets the data of the curve by reading the data from an array of values.
The values are read in the same order as the arguments of the method
{@link CubicCurve2D#setCurve(double, double, double, double, double, double, double, double)}
.
setCurve(coords[offset + 0], coords[offset + 1], coords[offset + 2], coords[offset + 3],
coords[offset + 4], coords[offset + 5], coords[offset + 6], coords[offset + 7]);
| public void | setCurve(java.awt.geom.Point2D[] points, int offset)Sets the data of the curve by reading the data from an array of points.
The values are read in the same order as the arguments of the method
{@link CubicCurve2D#setCurve(Point2D, Point2D, Point2D, Point2D)}
setCurve(points[offset + 0].getX(), points[offset + 0].getY(), points[offset + 1].getX(),
points[offset + 1].getY(), points[offset + 2].getX(), points[offset + 2].getY(),
points[offset + 3].getX(), points[offset + 3].getY());
| public void | setCurve(java.awt.geom.CubicCurve2D curve)Sets the data of the curve by copying it from another CubicCurve2D.
setCurve(curve.getX1(), curve.getY1(), curve.getCtrlX1(), curve.getCtrlY1(), curve
.getCtrlX2(), curve.getCtrlY2(), curve.getX2(), curve.getY2());
| public static int | solveCubic(double[] eqn)Finds the roots of the cubic polynomial. This is accomplished by finding
the (real) values of x that solve the following equation: eqn[3]*x*x*x +
eqn[2]*x*x + eqn[1]*x + eqn[0] = 0. The solutions are written back into
the array eqn starting from the index 0 in the array. The return value
tells how many array elements have been changed by this method call.
return solveCubic(eqn, eqn);
| public static int | solveCubic(double[] eqn, double[] res)Finds the roots of the cubic polynomial. This is accomplished by finding
the (real) values of x that solve the following equation: eqn[3]*x*x*x +
eqn[2]*x*x + eqn[1]*x + eqn[0] = 0. The solutions are written into the
array res starting from the index 0 in the array. The return value tells
how many array elements have been changed by this method call.
return Crossing.solveCubic(eqn, res);
| public void | subdivide(java.awt.geom.CubicCurve2D left, java.awt.geom.CubicCurve2D right)Creates the data for two cubic curves by dividing this curve in two. The
division point is the point on the curve that is closest to the average
of curve's two control points. The two new control points (nearest the
new endpoint) are computed by averaging the original control points with
the new endpoint. The data of this curve is left unchanged.
subdivide(this, left, right);
| public static void | subdivide(java.awt.geom.CubicCurve2D src, java.awt.geom.CubicCurve2D left, java.awt.geom.CubicCurve2D right)Creates the data for two cubic curves by dividing the specified curve in
two. The division point is the point on the curve that is closest to the
average of curve's two control points. The two new control points
(nearest the new endpoint) are computed by averaging the original control
points with the new endpoint. The data of the source curve is left
unchanged.
double x1 = src.getX1();
double y1 = src.getY1();
double cx1 = src.getCtrlX1();
double cy1 = src.getCtrlY1();
double cx2 = src.getCtrlX2();
double cy2 = src.getCtrlY2();
double x2 = src.getX2();
double y2 = src.getY2();
double cx = (cx1 + cx2) / 2.0;
double cy = (cy1 + cy2) / 2.0;
cx1 = (x1 + cx1) / 2.0;
cy1 = (y1 + cy1) / 2.0;
cx2 = (x2 + cx2) / 2.0;
cy2 = (y2 + cy2) / 2.0;
double ax = (cx1 + cx) / 2.0;
double ay = (cy1 + cy) / 2.0;
double bx = (cx2 + cx) / 2.0;
double by = (cy2 + cy) / 2.0;
cx = (ax + bx) / 2.0;
cy = (ay + by) / 2.0;
if (left != null) {
left.setCurve(x1, y1, cx1, cy1, ax, ay, cx, cy);
}
if (right != null) {
right.setCurve(cx, cy, bx, by, cx2, cy2, x2, y2);
}
| public static void | subdivide(double[] src, int srcOff, double[] left, int leftOff, double[] right, int rightOff)Creates the data for two cubic curves by dividing the specified curve in
two. The division point is the point on the curve that is closest to the
average of curve's two control points. The two new control points
(nearest the new endpoint) are computed by averaging the original control
points with the new endpoint. The data of the source curve is left
unchanged. The data for the three curves is read/written in the usual
order: { x1, y1, ctrlx1, ctrly1, ctrlx2, crtry2, x2, y3 }
double x1 = src[srcOff + 0];
double y1 = src[srcOff + 1];
double cx1 = src[srcOff + 2];
double cy1 = src[srcOff + 3];
double cx2 = src[srcOff + 4];
double cy2 = src[srcOff + 5];
double x2 = src[srcOff + 6];
double y2 = src[srcOff + 7];
double cx = (cx1 + cx2) / 2.0;
double cy = (cy1 + cy2) / 2.0;
cx1 = (x1 + cx1) / 2.0;
cy1 = (y1 + cy1) / 2.0;
cx2 = (x2 + cx2) / 2.0;
cy2 = (y2 + cy2) / 2.0;
double ax = (cx1 + cx) / 2.0;
double ay = (cy1 + cy) / 2.0;
double bx = (cx2 + cx) / 2.0;
double by = (cy2 + cy) / 2.0;
cx = (ax + bx) / 2.0;
cy = (ay + by) / 2.0;
if (left != null) {
left[leftOff + 0] = x1;
left[leftOff + 1] = y1;
left[leftOff + 2] = cx1;
left[leftOff + 3] = cy1;
left[leftOff + 4] = ax;
left[leftOff + 5] = ay;
left[leftOff + 6] = cx;
left[leftOff + 7] = cy;
}
if (right != null) {
right[rightOff + 0] = cx;
right[rightOff + 1] = cy;
right[rightOff + 2] = bx;
right[rightOff + 3] = by;
right[rightOff + 4] = cx2;
right[rightOff + 5] = cy2;
right[rightOff + 6] = x2;
right[rightOff + 7] = y2;
}
|
|