Line2Dpublic abstract class Line2D extends Object implements Shape, CloneableThe Class Line2D represents a line whose data is given in high-precision
values appropriate for graphical operations. |
Constructors Summary |
---|
protected Line2D()Instantiates a new Line2D.
|
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 false;
| public boolean | contains(java.awt.geom.Point2D p)
return false;
| public boolean | contains(java.awt.geom.Rectangle2D r)
return false;
| public boolean | contains(double rx, double ry, double rw, double rh)
return false;
| public java.awt.Rectangle | getBounds()
return getBounds2D().getBounds();
| public abstract java.awt.geom.Point2D | getP1()Gets the p the starting point.
| public abstract java.awt.geom.Point2D | getP2()Gets the p end point.
| public java.awt.geom.PathIterator | getPathIterator(java.awt.geom.AffineTransform at)
return new Iterator(this, at);
| public java.awt.geom.PathIterator | getPathIterator(java.awt.geom.AffineTransform at, double flatness)
return new Iterator(this, at);
| 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)
return intersects(new Rectangle2D.Double(rx, ry, rw, rh));
| public boolean | intersects(java.awt.geom.Rectangle2D r)
return r.intersectsLine(getX1(), getY1(), getX2(), getY2());
| public boolean | intersectsLine(double x1, double y1, double x2, double y2)Tells whether the specified line segments crosses this line segment.
return linesIntersect(x1, y1, x2, y2, getX1(), getY1(), getX2(), getY2());
| public boolean | intersectsLine(java.awt.geom.Line2D l)Tells whether the specified line segments crosses this line segment.
return linesIntersect(l.getX1(), l.getY1(), l.getX2(), l.getY2(), getX1(), getY1(),
getX2(), getY2());
| public static boolean | linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)Tells whether the two line segments cross.
/*
* A = (x2-x1, y2-y1) B = (x3-x1, y3-y1) C = (x4-x1, y4-y1) D = (x4-x3,
* y4-y3) = C-B E = (x1-x3, y1-y3) = -B F = (x2-x3, y2-y3) = A-B Result
* is ((AxB) (AxC) <=0) and ((DxE) (DxF) <= 0) DxE = (C-B)x(-B) =
* BxB-CxB = BxC DxF = (C-B)x(A-B) = CxA-CxB-BxA+BxB = AxB+BxC-AxC
*/
x2 -= x1; // A
y2 -= y1;
x3 -= x1; // B
y3 -= y1;
x4 -= x1; // C
y4 -= y1;
double AvB = x2 * y3 - x3 * y2;
double AvC = x2 * y4 - x4 * y2;
// Online
if (AvB == 0.0 && AvC == 0.0) {
if (x2 != 0.0) {
return (x4 * x3 <= 0.0)
|| ((x3 * x2 >= 0.0) && (x2 > 0.0 ? x3 <= x2 || x4 <= x2 : x3 >= x2
|| x4 >= x2));
}
if (y2 != 0.0) {
return (y4 * y3 <= 0.0)
|| ((y3 * y2 >= 0.0) && (y2 > 0.0 ? y3 <= y2 || y4 <= y2 : y3 >= y2
|| y4 >= y2));
}
return false;
}
double BvC = x3 * y4 - x4 * y3;
return (AvB * AvC <= 0.0) && (BvC * (AvB + BvC - AvC) <= 0.0);
| public static double | ptLineDist(double x1, double y1, double x2, double y2, double px, double py)Gives the square of the distance between the point and the line.
return Math.sqrt(ptLineDistSq(x1, y1, x2, y2, px, py));
| public double | ptLineDist(double px, double py)Gives the distance between the point and the line determined by this
Line2D.
return ptLineDist(getX1(), getY1(), getX2(), getY2(), px, py);
| public double | ptLineDist(java.awt.geom.Point2D p)Gives the distance between the point and the line determined by this
Line2D.
return ptLineDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
| public static double | ptLineDistSq(double x1, double y1, double x2, double y2, double px, double py)Gives the square of the distance between the point and the line.
x2 -= x1;
y2 -= y1;
px -= x1;
py -= y1;
double s = px * y2 - py * x2;
return s * s / (x2 * x2 + y2 * y2);
| public double | ptLineDistSq(double px, double py)Gives the square of the distance between the point and the line
determined by this Line2D.
return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), px, py);
| public double | ptLineDistSq(java.awt.geom.Point2D p)Gives the square of the distance between the point and the line
determined by this Line2D.
return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
| public static double | ptSegDist(double x1, double y1, double x2, double y2, double px, double py)Gives the distance between the point and the line segment.
return Math.sqrt(ptSegDistSq(x1, y1, x2, y2, px, py));
| public double | ptSegDist(double px, double py)Gives the distance between the point and this line segment.
return ptSegDist(getX1(), getY1(), getX2(), getY2(), px, py);
| public double | ptSegDist(java.awt.geom.Point2D p)Gives the distance between the point and this line segment.
return ptSegDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
| public static double | ptSegDistSq(double x1, double y1, double x2, double y2, double px, double py)Gives the square of the distance between the point and the line segment.
/*
* A = (x2 - x1, y2 - y1) P = (px - x1, py - y1)
*/
x2 -= x1; // A = (x2, y2)
y2 -= y1;
px -= x1; // P = (px, py)
py -= y1;
double dist;
if (px * x2 + py * y2 <= 0.0) { // P*A
dist = px * px + py * py;
} else {
px = x2 - px; // P = A - P = (x2 - px, y2 - py)
py = y2 - py;
if (px * x2 + py * y2 <= 0.0) { // P*A
dist = px * px + py * py;
} else {
dist = px * y2 - py * x2;
dist = dist * dist / (x2 * x2 + y2 * y2); // pxA/|A|
}
}
if (dist < 0) {
dist = 0;
}
return dist;
| public double | ptSegDistSq(double px, double py)Gives the square of the distance between the point and this line segment.
return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), px, py);
| public double | ptSegDistSq(java.awt.geom.Point2D p)Gives the square of the distance between the point and this line segment.
return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
| public static int | relativeCCW(double x1, double y1, double x2, double y2, double px, double py)Tells where the point is with respect to the line segment, given the
orientation of the line segment. If the ray found by extending the line
segment from its starting point is rotated, this method tells whether the
ray should rotate in a clockwise direction or a counter-clockwise
direction to hit the point first. The return value is 0 if the point is
on the line segment, it's 1 if the point is on the ray or if the ray
should rotate in a counter-clockwise direction to get to the point, and
it's -1 if the ray should rotate in a clockwise direction to get to the
point or if the point is on the line determined by the line segment but
not on the ray from the segment's starting point and through its end
point.
/*
* A = (x2-x1, y2-y1) P = (px-x1, py-y1)
*/
x2 -= x1;
y2 -= y1;
px -= x1;
py -= y1;
double t = px * y2 - py * x2; // PxA
if (t == 0.0) {
t = px * x2 + py * y2; // P*A
if (t > 0.0) {
px -= x2; // B-A
py -= y2;
t = px * x2 + py * y2; // (P-A)*A
if (t < 0.0) {
t = 0.0;
}
}
}
return t < 0.0 ? -1 : (t > 0.0 ? 1 : 0);
| public int | relativeCCW(double px, double py)Tells where the point is with respect to this line segment, given the
orientation of this line segment. If the ray found by extending the line
segment from its starting point is rotated, this method tells whether the
ray should rotate in a clockwise direction or a counter-clockwise
direction to hit the point first. The return value is 0 if the point is
on the line segment, it's 1 if the point is on the ray or if the ray
should rotate in a counter-clockwise direction to get to the point, and
it's -1 if the ray should rotate in a clockwise direction to get to the
point or if the point is on the line determined by the line segment but
not on the ray from the segment's starting point and through its end
point.
return relativeCCW(getX1(), getY1(), getX2(), getY2(), px, py);
| public int | relativeCCW(java.awt.geom.Point2D p)Tells where the point is with respect to this line segment, given the
orientation of this line segment. If the ray found by extending the line
segment from its starting point is rotated, this method tells whether the
ray should rotate in a clockwise direction or a counter-clockwise
direction to hit the point first. The return value is 0 if the point is
on the line segment, it's 1 if the point is on the ray or if the ray
should rotate in a counter-clockwise direction to get to the point, and
it's -1 if the ray should rotate in a clockwise direction to get to the
point or if the point is on the line determined by the line segment but
not on the ray from the segment's starting point and through its end
point.
return relativeCCW(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
| public void | setLine(java.awt.geom.Line2D line)Sets the line's endpoints by copying the data from another Line2D.
setLine(line.getX1(), line.getY1(), line.getX2(), line.getY2());
| public abstract void | setLine(double x1, double y1, double x2, double y2)Sets the line's endpoints.
| public void | setLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)Sets the line's endpoints.
setLine(p1.getX(), p1.getY(), p2.getX(), p2.getY());
|
|