Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.awt.geom.Line2D
Nested Class Summary | |
static class |
|
static class |
|
Constructor Summary | |
|
Method Summary | |
Object |
|
boolean |
|
boolean |
|
boolean | |
boolean |
|
Rectangle |
|
abstract Point2D |
|
abstract Point2D |
|
PathIterator |
|
PathIterator |
|
abstract double |
|
abstract double |
|
abstract double |
|
abstract double |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
static boolean |
|
double |
|
static double |
|
double |
|
double |
|
static double |
|
double |
|
double |
|
static double |
|
double | |
double |
|
static double |
|
double |
|
int |
|
static int |
|
int |
|
abstract void |
|
void | |
void |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public Object clone()
Create a new line of the same run-time type with the same contents as this one.
- Returns:
- the clone
- Since:
- 1.2
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:
x
- the x coordinatey
- the y coordinate
- Returns:
- false; the line does not contain points
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:
x
- the x coordinate of the rectangley
- the y coordinate of the rectanglew
- the width of the rectangleh
- the height of the rectangle
- Returns:
- false; the line does not contain points
public boolean contains(Point2D p)
Test if a point is contained inside the line. Since a line has no area, this returns false.
- Parameters:
p
- the point
- Returns:
- false; the line does not contain points
public boolean contains(Rectangle2D r)
Tests if the line contains a rectangle. Since lines have no area, this always returns false.
- Parameters:
r
- the rectangle
- Returns:
- false; the line does not contain points
public Rectangle getBounds()
Gets a bounding box (not necessarily minimal) for this line.
- Returns:
- the integer bounding box
- See Also:
getBounds2D()
public PathIterator getPathIterator(AffineTransform at)
Return a path iterator, possibly applying a transform on the result. This iterator is not threadsafe.
- Specified by:
- getPathIterator in interface Shape
- Parameters:
at
- the transform, or null
- Returns:
- a new path iterator
public PathIterator getPathIterator(AffineTransform at, double flatness)
Return a flat path iterator, possibly applying a transform on the result. This iterator is not threadsafe.
- Specified by:
- getPathIterator in interface Shape
- Parameters:
at
- the transform, or nullflatness
- ignored, since lines are already flat
- Returns:
- a new path iterator
- See Also:
getPathIterator(AffineTransform)
public abstract double getX1()
Return the x coordinate of the first point.
- Returns:
- the starting x coordinate
public abstract double getX2()
Return the x coordinate of the second point.
- Returns:
- the ending x coordinate
public abstract double getY1()
Return the y coordinate of the first point.
- Returns:
- the starting y coordinate
public abstract double getY2()
Return the y coordinate of the second point.
- Returns:
- the ending y coordinate
public boolean intersects(double x, double y, double w, double h)
Tests if this line intersects the interior of the specified rectangle.
- Specified by:
- intersects in interface Shape
- Parameters:
x
- the x coordinate of the rectangley
- the y coordinate of the rectanglew
- the width of the rectangleh
- the height of the rectangle
- Returns:
- true if the line intersects the rectangle
public boolean intersects(Rectangle2D r)
Tests if this line intersects the interior of the specified rectangle.
- Specified by:
- intersects in interface Shape
- Parameters:
r
- the rectangle
- Returns:
- true if the line intersects the rectangle
- Throws:
NullPointerException
- if r is null
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:
x1
- the first x coordinate of the other segmenty1
- the first y coordinate of the other segmentx2
- the second x coordinate of the other segmenty2
- the second y coordinate of the other segment
- Returns:
- true if the segments intersect
public boolean intersectsLine(Line2D l)
Test if this line intersects the given line.
- Parameters:
l
- the other segment
- Returns:
- true if the segments intersect
- Throws:
NullPointerException
- if l is null
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:
x1
- the first x coordinate of the first segmenty1
- the first y coordinate of the first segmentx2
- the second x coordinate of the first segmenty2
- the second y coordinate of the first segmentx3
- the first x coordinate of the second segmenty3
- the first y coordinate of the second segmentx4
- the second x coordinate of the second segmenty4
- the second y coordinate of the second segment
- Returns:
- true if the segments intersect
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:
px
- the x coordinate of the pointpy
- the y coordinate of the point
- Returns:
- the distance from the point to the extended line
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:
x1
- the first x coordinate of the segmenty1
- the first y coordinate of the segmentx2
- the second x coordinate of the segmenty2
- the second y coordinate of the segmentpx
- the x coordinate of the pointpy
- the y coordinate of the point
- Returns:
- the distance from the point to the extended line
public double ptLineDist(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:
p
- the point
- Returns:
- the distance from the point to the extended line
- Throws:
NullPointerException
- if p is null
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:
px
- the x coordinate of the pointpy
- the y coordinate of the point
- Returns:
- the square of the distance from the point to the extended line
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:
x1
- the first x coordinate of the segmenty1
- the first y coordinate of the segmentx2
- the second x coordinate of the segmenty2
- the second y coordinate of the segmentpx
- the x coordinate of the pointpy
- the y coordinate of the point
- Returns:
- the square of the distance from the point to the extended line
public double ptLineDistSq(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:
p
- the point
- Returns:
- the square of the distance from the point to the extended line
- Throws:
NullPointerException
- if p is null
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:
px
- the x coordinate of the pointpy
- the y coordinate of the point
- Returns:
- the distance from the point to the segment
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:
x1
- the first x coordinate of the segmenty1
- the first y coordinate of the segmentx2
- the second x coordinate of the segmenty2
- the second y coordinate of the segmentpx
- the x coordinate of the pointpy
- the y coordinate of the point
- Returns:
- the distance from the point to the segment
public double ptSegDist(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:
p
- the point
- Returns:
- the distance from the point to the segment
- Throws:
NullPointerException
- if p is null
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:
px
- the x coordinate of the pointpy
- the y coordinate of the point
- Returns:
- the square of the distance from the point to the segment
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:
x1
- the first x coordinate of the segmenty1
- the first y coordinate of the segmentx2
- the second x coordinate of the segmenty2
- the second y coordinate of the segmentpx
- the x coordinate of the pointpy
- the y coordinate of the point
- Returns:
- the square of the distance from the point to the segment
public double ptSegDistSq(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:
p
- the point
- Returns:
- the square of the distance from the point to the segment
- Throws:
NullPointerException
- if p is null
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:
px
- the reference x coordinatepy
- the reference y coordinate
- Returns:
- the relative rotation direction
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:
x1
- the first x coordinatey1
- the first y coordinatex2
- the second x coordinatey2
- the second y coordinatepx
- the reference x coordinatepy
- the reference y coordinate
- Returns:
- the relative rotation direction
public int relativeCCW(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:
p
- the reference point
- Returns:
- the relative rotation direction
- Throws:
NullPointerException
- if p is null
public abstract 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:
x1
- the first x coordinatey1
- the first y coordinatex2
- the second x coordinatey2
- the second y coordinate
public void setLine(Line2D l)
Set the coordinates to those of the given line.
- Parameters:
l
- the line to copy
- Throws:
NullPointerException
- if l is null
public void setLine(Point2D p1, Point2D p2)
Set the coordinates to the given points.
- Parameters:
p1
- the first pointp2
- the second point
- Throws:
NullPointerException
- if either point is null