QuadCurve2Dpublic abstract class QuadCurve2D extends Object implements Shape, CloneableThe Class QuadCurve2D is a Shape that represents a segment of a quadratic
(Bezier) curve. The curved segment is determined by three points: a start
point, an end point, and a control point. The line from the control point to
the starting point gives the tangent to the curve at the starting point, and
the line from the control point to the end point gives the tangent to the
curve at the end point. |
Constructors Summary |
---|
protected QuadCurve2D()Instantiates a new quadratic 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 | getCtrlPt()Gets the control point.
| public abstract double | getCtrlX()Gets the x coordinate of the control point.
| public abstract double | getCtrlY()Gets the y coordinate of the control point.
| public double | getFlatness()Gets the distance from the control point to the straight line segment
connecting the start point and the end point of this QuadCurve2D.
return Line2D.ptSegDist(getX1(), getY1(), getX2(), getY2(), getCtrlX(), getCtrlY());
| public static double | getFlatness(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)Gets the distance from the control point to the straight line segment
connecting the start point and the end point.
return Line2D.ptSegDist(x1, y1, x2, y2, ctrlx, ctrly);
| public static double | getFlatness(double[] coords, int offset)Gets the the distance from the control point to the straight line segment
connecting the start point and the end point. The values are read in the
same order as the arguments of the method
{@link QuadCurve2D#getFlatness(double, double, double, double, double, double)}
.
return Line2D.ptSegDist(coords[offset + 0], coords[offset + 1], coords[offset + 4],
coords[offset + 5], coords[offset + 2], coords[offset + 3]);
| public double | getFlatnessSq()Gets the square of the distance from the control point to the straight
line segment connecting the start point and the end point for this curve.
return Line2D.ptSegDistSq(getX1(), getY1(), getX2(), getY2(), getCtrlX(), getCtrlY());
| public static double | getFlatnessSq(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)Gets the square of the distance from the control point to the straight
line segment connecting the start point and the end point.
return Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx, ctrly);
| public static double | getFlatnessSq(double[] coords, int offset)Gets the square of the distance from the control point to the straight
line segment connecting the start point and the end point by reading the
coordinates of the points from an array of values. The values are read in
the same order as the arguments of the method
{@link QuadCurve2D#getFlatnessSq(double, double, double, double, double, double)}
.
return Line2D.ptSegDistSq(coords[offset + 0], coords[offset + 1], coords[offset + 4],
coords[offset + 5], coords[offset + 2], coords[offset + 3]);
| 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 t, double flatness)
return new FlatteningPathIterator(getPathIterator(t), 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 ctrlx, double ctrly, double x2, double y2)Sets the data of the curve.
| public void | setCurve(java.awt.geom.Point2D p1, java.awt.geom.Point2D cp, java.awt.geom.Point2D p2)Sets the data of the curve.
setCurve(p1.getX(), p1.getY(), cp.getX(), cp.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 QuadCurve2D#setCurve(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]);
| 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 QuadCurve2D#setCurve(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());
| public void | setCurve(java.awt.geom.QuadCurve2D curve)Sets the data of the curve by copying it from another QuadCurve2D.
setCurve(curve.getX1(), curve.getY1(), curve.getCtrlX(), curve.getCtrlY(), curve.getX2(),
curve.getY2());
| public static int | solveQuadratic(double[] eqn)Finds the roots of the quadratic polynomial. This is accomplished by
finding the (real) values of x that solve the following equation:
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 solveQuadratic(eqn, eqn);
| public static int | solveQuadratic(double[] eqn, double[] res)Finds the roots of the quadratic polynomial. This is accomplished by
finding the (real) values of x that solve the following equation:
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 written by this method call.
return Crossing.solveQuad(eqn, res);
| public void | subdivide(java.awt.geom.QuadCurve2D left, java.awt.geom.QuadCurve2D right)Creates the data for two quadratic curves by dividing this curve in two.
The division point is the point on the curve that is closest to this
curve's control point. The data of this curve is left unchanged.
subdivide(this, left, right);
| public static void | subdivide(java.awt.geom.QuadCurve2D src, java.awt.geom.QuadCurve2D left, java.awt.geom.QuadCurve2D right)Creates the data for two quadratic curves by dividing a source curve in
two. The division point is the point on the curve that is closest to the
source curve's control point. The data of the source curve is left
unchanged.
double x1 = src.getX1();
double y1 = src.getY1();
double cx = src.getCtrlX();
double cy = src.getCtrlY();
double x2 = src.getX2();
double y2 = src.getY2();
double cx1 = (x1 + cx) / 2.0;
double cy1 = (y1 + cy) / 2.0;
double cx2 = (x2 + cx) / 2.0;
double cy2 = (y2 + cy) / 2.0;
cx = (cx1 + cx2) / 2.0;
cy = (cy1 + cy2) / 2.0;
if (left != null) {
left.setCurve(x1, y1, cx1, cy1, cx, cy);
}
if (right != null) {
right.setCurve(cx, cy, 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 quadratic curves by dividing a source curve in
two. The division point is the point on the curve that is closest to the
source curve's control point. The data for the three curves is read and
written from arrays of values in the usual order: x1, y1, cx, cy, x2, y2.
double x1 = src[srcoff + 0];
double y1 = src[srcoff + 1];
double cx = src[srcoff + 2];
double cy = src[srcoff + 3];
double x2 = src[srcoff + 4];
double y2 = src[srcoff + 5];
double cx1 = (x1 + cx) / 2.0;
double cy1 = (y1 + cy) / 2.0;
double cx2 = (x2 + cx) / 2.0;
double cy2 = (y2 + cy) / 2.0;
cx = (cx1 + cx2) / 2.0;
cy = (cy1 + cy2) / 2.0;
if (left != null) {
left[leftOff + 0] = x1;
left[leftOff + 1] = y1;
left[leftOff + 2] = cx1;
left[leftOff + 3] = cy1;
left[leftOff + 4] = cx;
left[leftOff + 5] = cy;
}
if (right != null) {
right[rightOff + 0] = cx;
right[rightOff + 1] = cy;
right[rightOff + 2] = cx2;
right[rightOff + 3] = cy2;
right[rightOff + 4] = x2;
right[rightOff + 5] = y2;
}
|
|