java.awt.geom
Class Line2D
java.lang.Object
|
+--java.awt.geom.Line2D
All Implemented Interfaces:
Shape, Cloneable
Represents a directed line bewteen two points in (x,y) Cartesian space.
Remember, on-screen graphics have increasing x from left-to-right, and
increasing y from top-to-bottom. The storage is left to subclasses.
Since:Authors:- Tom Tromey <tromey@cygnus.com>
- Eric Blake <ebb9@email.byu.edu>
java.lang.Object | clone()
|
boolean | contains(double x, double y)
|
boolean | contains(java.awt.geom.Point2D p)
|
boolean | contains(double x, double y, double w, double h)
|
boolean | contains(java.awt.geom.Rectangle2D r)
|
java.awt.Rectangle | getBounds()
|
java.awt.geom.Point2D | getP1()
|
java.awt.geom.Point2D | getP2()
|
java.awt.geom.PathIterator | getPathIterator(final AffineTransform at)
|
java.awt.geom.PathIterator | getPathIterator(java.awt.geom.AffineTransform at, double flatness)
|
double | getX1()
|
double | getX2()
|
double | getY1()
|
double | getY2()
|
boolean | intersects(double x, double y, double w, double h)
|
boolean | intersects(java.awt.geom.Rectangle2D r)
|
boolean | intersectsLine(double x1, double y1, double x2, double y2)
|
boolean | intersectsLine(java.awt.geom.Line2D l)
|
static boolean | linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
|
static double | ptLineDist(double x1, double y1, double x2, double y2, double px, double py)
|
double | ptLineDist(double px, double py)
|
double | ptLineDist(java.awt.geom.Point2D p)
|
static double | ptLineDistSq(double x1, double y1, double x2, double y2, double px, double py)
|
double | ptLineDistSq(double px, double py)
|
double | ptLineDistSq(java.awt.geom.Point2D p)
|
static double | ptSegDist(double x1, double y1, double x2, double y2, double px, double py)
|
double | ptSegDist(double px, double py)
|
double | ptSegDist(java.awt.geom.Point2D p)
|
static double | ptSegDistSq(double x1, double y1, double x2, double y2, double px, double py)
|
double | ptSegDistSq(double px, double py)
|
double | ptSegDistSq(java.awt.geom.Point2D p)
|
static int | relativeCCW(double x1, double y1, double x2, double y2, double px, double py)
|
int | relativeCCW(double px, double py)
|
int | relativeCCW(java.awt.geom.Point2D p)
|
void | setLine(double x1, double y1, double x2, double y2)
|
void | setLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
|
void | setLine(java.awt.geom.Line2D l)
|
Line2D
protected Line2D()
The default constructor.
clone
public Object clone()
Create a new line of the same run-time type with the same contents as
this one.
Since:Returns:
Throws:
contains
public boolean contains(double x, double y)
Test if a point is contained inside the line. Since a line has no area,
this returns false.
Parameters:
Returns:
- false; the line does not contain points
contains
public boolean contains(double x, double y, double w, double h)
Tests if the line contains a rectangle. Since lines have no area, this
always returns false.
Parameters:
Returns:
- false; the line does not contain points
contains
public boolean contains(java.awt.geom.Point2D p)
Test if a point is contained inside the line. Since a line has no area,
this returns false.
Parameters:
Returns:
- false; the line does not contain points
contains
public boolean contains(java.awt.geom.Rectangle2D r)
Tests if the line contains a rectangle. Since lines have no area, this
always returns false.
Parameters:
Returns:
- false; the line does not contain points
getBounds
public Rectangle getBounds()
Gets a bounding box (not necessarily minimal) for this line.
Returns:
See Also:
getP1
public Point2D getP1()
Return the first point.
Returns:
getP2
public Point2D getP2()
Return the second point.
Returns:
getPathIterator
public PathIterator getPathIterator(final AffineTransform at)
Return a path iterator, possibly applying a transform on the result. This
iterator is not threadsafe.
Parameters:
Returns:
getPathIterator
public PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)
Return a flat path iterator, possibly applying a transform on the result.
This iterator is not threadsafe.
Parameters:
Returns:
See Also:
getX1
public double getX1()
Return the x coordinate of the first point.
Returns:
- the starting x coordinate
getX2
public double getX2()
Return the x coordinate of the second point.
Returns:
getY1
public double getY1()
Return the y coordinate of the first point.
Returns:
- the starting y coordinate
getY2
public double getY2()
Return the y coordinate of the second point.
Returns:
intersects
public boolean intersects(double x, double y, double w, double h)
Tests if this line intersects the interior of the specified rectangle.
Parameters:
Returns:
- true if the line intersects the rectangle
intersects
public boolean intersects(java.awt.geom.Rectangle2D r)
Tests if this line intersects the interior of the specified rectangle.
Parameters:
Returns:
- true if the line intersects the rectangle
Throws:
intersectsLine
public boolean intersectsLine(double x1, double y1, double x2, double y2)
Test if this line intersects the line given by (x1,y1)->(x2,y2).
Parameters:
Returns:
- true if the segments intersect
See Also:
intersectsLine
public boolean intersectsLine(java.awt.geom.Line2D l)
Test if this line intersects the given line.
Parameters:
Returns:
- true if the segments intersect
Throws:
See Also:
linesIntersect
public static boolean linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
Test if the line segment (x1,y1)->(x2,y2) intersects the line segment
(x3,y3)->(x4,y4).
Parameters:
Returns:
- true if the segments intersect
ptLineDist
public double ptLineDist(double px, double py)
Measures the shortest distance from the reference point to a point on
the infinite line extended from this segment. If the point is on the
segment, the result will be 0. If the segment is length 0, the distance
is to the common endpoint.
Parameters:
Returns:
- the distance from the point to the extended line
See Also:
ptLineDist
public static double ptLineDist(double x1, double y1, double x2, double y2, double px, double py)
Measures the shortest distance from the reference point to a point on
the infinite line extended from the segment. If the point is on the
segment, the result will be 0. If the segment is length 0, the distance
is to the common endpoint.
Parameters:
Returns:
- the distance from the point to the extended line
See Also:
ptLineDist
public double ptLineDist(java.awt.geom.Point2D p)
Measures the shortest distance from the reference point to a point on
the infinite line extended from this segment. If the point is on the
segment, the result will be 0. If the segment is length 0, the distance
is to the common endpoint.
Parameters:
Returns:
- the distance from the point to the extended line
Throws:
See Also:
ptLineDistSq
public double ptLineDistSq(double px, double py)
Measures the square of the shortest distance from the reference point
to a point on the infinite line extended from this segment. If the point
is on the segment, the result will be 0. If the segment is length 0,
the distance is to the common endpoint.
Parameters:
Returns:
- the square of the distance from the point to the extended line
See Also:
ptLineDistSq
public static double ptLineDistSq(double x1, double y1, double x2, double y2, double px, double py)
Measures the square of the shortest distance from the reference point
to a point on the infinite line extended from the segment. If the point
is on the segment, the result will be 0. If the segment is length 0,
the distance is to the common endpoint.
Parameters:
Returns:
- the square of the distance from the point to the extended line
See Also:
ptLineDistSq
public double ptLineDistSq(java.awt.geom.Point2D p)
Measures the square of the shortest distance from the reference point
to a point on the infinite line extended from this segment. If the point
is on the segment, the result will be 0. If the segment is length 0,
the distance is to the common endpoint.
Parameters:
Returns:
- the square of the distance from the point to the extended line
Throws:
See Also:
ptSegDist
public double ptSegDist(double px, double py)
Measures the shortest distance from the reference point to a point on
this line segment. If the point is on the segment, the result will be 0.
Parameters:
Returns:
- the distance from the point to the segment
See Also:
ptSegDist
public static double ptSegDist(double x1, double y1, double x2, double y2, double px, double py)
Measures the shortest distance from the reference point to a point on
the line segment. If the point is on the segment, the result will be 0.
Parameters:
Returns:
- the distance from the point to the segment
See Also:
ptSegDist
public double ptSegDist(java.awt.geom.Point2D p)
Measures the shortest distance from the reference point to a point on
this line segment. If the point is on the segment, the result will be 0.
Parameters:
Returns:
- the distance from the point to the segment
Throws:
See Also:
ptSegDistSq
public double ptSegDistSq(double px, double py)
Measures the square of the shortest distance from the reference point
to a point on this line segment. If the point is on the segment, the
result will be 0.
Parameters:
Returns:
- the square of the distance from the point to the segment
See Also:
ptSegDistSq
public static double ptSegDistSq(double x1, double y1, double x2, double y2, double px, double py)
Measures the square of the shortest distance from the reference point
to a point on the line segment. If the point is on the segment, the
result will be 0.
Parameters:
Returns:
- the square of the distance from the point to the segment
See Also:
ptSegDistSq
public double ptSegDistSq(java.awt.geom.Point2D p)
Measures the square of the shortest distance from the reference point
to a point on this line segment. If the point is on the segment, the
result will be 0.
Parameters:
Returns:
- the square of the distance from the point to the segment
Throws:
See Also:
relativeCCW
public int relativeCCW(double px, double py)
Computes the relative rotation direction needed to pivot this line about
the first point in order to have the second point colinear with point p.
Because of floating point rounding, don't expect this to be a perfect
measure of colinearity. The answer is 1 if the line has a shorter rotation
in the direction of the positive X axis to the negative Y axis
(counter-clockwise in the default Java coordinate system), or -1 if the
shortest rotation is in the opposite direction (clockwise). If p
is already colinear, the return value is -1 if it lies beyond the first
point, 0 if it lies in the segment, or 1 if it lies beyond the second
point. If the first and second point are coincident, this returns 0.
Parameters:
Returns:
- the relative rotation direction
See Also:
relativeCCW
public static int relativeCCW(double x1, double y1, double x2, double y2, double px, double py)
Computes the relative rotation direction needed to pivot the line about
the first point in order to have the second point colinear with point p.
Because of floating point rounding, don't expect this to be a perfect
measure of colinearity. The answer is 1 if the line has a shorter rotation
in the direction of the positive X axis to the negative Y axis
(counter-clockwise in the default Java coordinate system), or -1 if the
shortest rotation is in the opposite direction (clockwise). If p
is already colinear, the return value is -1 if it lies beyond the first
point, 0 if it lies in the segment, or 1 if it lies beyond the second
point. If the first and second point are coincident, this returns 0.
Parameters:
Returns:
- the relative rotation direction
relativeCCW
public int relativeCCW(java.awt.geom.Point2D p)
Computes the relative rotation direction needed to pivot this line about
the first point in order to have the second point colinear with point p.
Because of floating point rounding, don't expect this to be a perfect
measure of colinearity. The answer is 1 if the line has a shorter rotation
in the direction of the positive X axis to the negative Y axis
(counter-clockwise in the default Java coordinate system), or -1 if the
shortest rotation is in the opposite direction (clockwise). If p
is already colinear, the return value is -1 if it lies beyond the first
point, 0 if it lies in the segment, or 1 if it lies beyond the second
point. If the first and second point are coincident, this returns 0.
Parameters:
Returns:
- the relative rotation direction
Throws:
See Also:
setLine
public void setLine(double x1, double y1, double x2, double y2)
Set the coordinates of the line to the given coordinates. Loss of
precision may occur due to rounding issues.
Parameters:
setLine
public void setLine(java.awt.geom.Line2D l)
Set the coordinates to those of the given line.
Parameters:
Throws:
setLine
public void setLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
Set the coordinates to the given points.
Parameters:
Throws: