Class Line2D
 Direct Known Subclasses:
Line2D.Double
,Line2D.Float
Line2D
represents a line segment in (x,y)
coordinate space.
This class is only the abstract superclass for all objects that store a 2D line segment. The actual storage representation of the coordinates is left to the subclass.
 Since:
 1.2

Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A line segment specified with double coordinates.static class
A line segment specified with float coordinates. 
Constructor Summary
ModifierConstructorDescriptionprotected
Line2D()
This is an abstract class that cannot be instantiated directly. 
Method Summary
Modifier and TypeMethodDescriptionclone()
Creates a new object of the same class as this object.boolean
contains
(double x, double y) Tests if a specified coordinate is inside the boundary of thisLine2D
.boolean
contains
(double x, double y, double w, double h) Tests if the interior of thisLine2D
entirely contains the specified set of rectangular coordinates.boolean
Tests if a givenPoint2D
is inside the boundary of thisLine2D
.boolean
Tests if the interior of thisLine2D
entirely contains the specifiedRectangle2D
.Returns an integerRectangle
that completely encloses theShape
.abstract Point2D
getP1()
Returns the startPoint2D
of thisLine2D
.abstract Point2D
getP2()
Returns the endPoint2D
of thisLine2D
.Returns an iteration object that defines the boundary of thisLine2D
.getPathIterator
(AffineTransform at, double flatness) Returns an iteration object that defines the boundary of this flattenedLine2D
.abstract double
getX1()
Returns the X coordinate of the start point in double precision.abstract double
getX2()
Returns the X coordinate of the end point in double precision.abstract double
getY1()
Returns the Y coordinate of the start point in double precision.abstract double
getY2()
Returns the Y coordinate of the end point in double precision.boolean
intersects
(double x, double y, double w, double h) Tests if the interior of theShape
intersects the interior of a specified rectangular area.boolean
Tests if the interior of theShape
intersects the interior of a specifiedRectangle2D
.boolean
intersectsLine
(double x1, double y1, double x2, double y2) Tests if the line segment from(x1,y1)
to(x2,y2)
intersects this line segment.boolean
Tests if the specified line segment intersects this line segment.static boolean
linesIntersect
(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) Tests if the line segment from(x1,y1)
to(x2,y2)
intersects the line segment from(x3,y3)
to(x4,y4)
.double
ptLineDist
(double px, double py) Returns the distance from a point to this line.static double
ptLineDist
(double x1, double y1, double x2, double y2, double px, double py) Returns the distance from a point to a line.double
ptLineDist
(Point2D pt) Returns the distance from aPoint2D
to this line.double
ptLineDistSq
(double px, double py) Returns the square of the distance from a point to this line.static double
ptLineDistSq
(double x1, double y1, double x2, double y2, double px, double py) Returns the square of the distance from a point to a line.double
ptLineDistSq
(Point2D pt) Returns the square of the distance from a specifiedPoint2D
to this line.double
ptSegDist
(double px, double py) Returns the distance from a point to this line segment.static double
ptSegDist
(double x1, double y1, double x2, double y2, double px, double py) Returns the distance from a point to a line segment.double
Returns the distance from aPoint2D
to this line segment.double
ptSegDistSq
(double px, double py) Returns the square of the distance from a point to this line segment.static double
ptSegDistSq
(double x1, double y1, double x2, double y2, double px, double py) Returns the square of the distance from a point to a line segment.double
ptSegDistSq
(Point2D pt) Returns the square of the distance from aPoint2D
to this line segment.int
relativeCCW
(double px, double py) Returns an indicator of where the specified point(px,py)
lies with respect to this line segment.static int
relativeCCW
(double x1, double y1, double x2, double y2, double px, double py) Returns an indicator of where the specified point(px,py)
lies with respect to the line segment from(x1,y1)
to(x2,y2)
.int
Returns an indicator of where the specifiedPoint2D
lies with respect to this line segment.abstract void
setLine
(double x1, double y1, double x2, double y2) Sets the location of the end points of thisLine2D
to the specified double coordinates.void
Sets the location of the end points of thisLine2D
to the same as those end points of the specifiedLine2D
.void
Sets the location of the end points of thisLine2D
to the specifiedPoint2D
coordinates.Methods declared in class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface java.awt.Shape
getBounds2D

Constructor Details

Line2D
protected Line2D()This is an abstract class that cannot be instantiated directly. Typespecific implementation subclasses are available for instantiation and provide a number of formats for storing the information necessary to satisfy the various accessory methods below. Since:
 1.2
 See Also:


Method Details

getX1
public abstract double getX1()Returns the X coordinate of the start point in double precision. Returns:
 the X coordinate of the start point of this
Line2D
object.  Since:
 1.2

getY1
public abstract double getY1()Returns the Y coordinate of the start point in double precision. Returns:
 the Y coordinate of the start point of this
Line2D
object.  Since:
 1.2

getP1
Returns the startPoint2D
of thisLine2D
. Returns:
 the start
Point2D
of thisLine2D
.  Since:
 1.2

getX2
public abstract double getX2()Returns the X coordinate of the end point in double precision. Returns:
 the X coordinate of the end point of this
Line2D
object.  Since:
 1.2

getY2
public abstract double getY2()Returns the Y coordinate of the end point in double precision. Returns:
 the Y coordinate of the end point of this
Line2D
object.  Since:
 1.2

getP2
Returns the endPoint2D
of thisLine2D
. Returns:
 the end
Point2D
of thisLine2D
.  Since:
 1.2

setLine
public abstract void setLine(double x1, double y1, double x2, double y2) Sets the location of the end points of thisLine2D
to the specified double coordinates. Parameters:
x1
 the X coordinate of the start pointy1
 the Y coordinate of the start pointx2
 the X coordinate of the end pointy2
 the Y coordinate of the end point Since:
 1.2

setLine

setLine
Sets the location of the end points of thisLine2D
to the same as those end points of the specifiedLine2D
. Parameters:
l
 the specifiedLine2D
 Since:
 1.2

relativeCCW
public static int relativeCCW(double x1, double y1, double x2, double y2, double px, double py) Returns an indicator of where the specified point(px,py)
lies with respect to the line segment from(x1,y1)
to(x2,y2)
. The return value can be either 1, 1, or 0 and indicates in which direction the specified line must pivot around its first end point,(x1,y1)
, in order to point at the specified point(px,py)
.A return value of 1 indicates that the line segment must turn in the direction that takes the positive X axis towards the negative Y axis. In the default coordinate system used by Java 2D, this direction is counterclockwise.
A return value of 1 indicates that the line segment must turn in the direction that takes the positive X axis towards the positive Y axis. In the default coordinate system, this direction is clockwise.
A return value of 0 indicates that the point lies exactly on the line segment. Note that an indicator value of 0 is rare and not useful for determining collinearity because of floating point rounding issues.
If the point is colinear with the line segment, but not between the end points, then the value will be 1 if the point lies "beyond
(x1,y1)
" or 1 if the point lies "beyond(x2,y2)
". Parameters:
x1
 the X coordinate of the start point of the specified line segmenty1
 the Y coordinate of the start point of the specified line segmentx2
 the X coordinate of the end point of the specified line segmenty2
 the Y coordinate of the end point of the specified line segmentpx
 the X coordinate of the specified point to be compared with the specified line segmentpy
 the Y coordinate of the specified point to be compared with the specified line segment Returns:
 an integer that indicates the position of the third specified coordinates with respect to the line segment formed by the first two specified coordinates.
 Since:
 1.2

relativeCCW
public int relativeCCW(double px, double py) Returns an indicator of where the specified point(px,py)
lies with respect to this line segment. See the method comments ofrelativeCCW(double, double, double, double, double, double)
to interpret the return value. Parameters:
px
 the X coordinate of the specified point to be compared with thisLine2D
py
 the Y coordinate of the specified point to be compared with thisLine2D
 Returns:
 an integer that indicates the position of the specified
coordinates with respect to this
Line2D
 Since:
 1.2
 See Also:

relativeCCW
Returns an indicator of where the specifiedPoint2D
lies with respect to this line segment. See the method comments ofrelativeCCW(double, double, double, double, double, double)
to interpret the return value. Parameters:
p
 the specifiedPoint2D
to be compared with thisLine2D
 Returns:
 an integer that indicates the position of the specified
Point2D
with respect to thisLine2D
 Since:
 1.2
 See Also:

linesIntersect
public static boolean linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) Tests if the line segment from(x1,y1)
to(x2,y2)
intersects the line segment from(x3,y3)
to(x4,y4)
. Parameters:
x1
 the X coordinate of the start point of the first specified line segmenty1
 the Y coordinate of the start point of the first specified line segmentx2
 the X coordinate of the end point of the first specified line segmenty2
 the Y coordinate of the end point of the first specified line segmentx3
 the X coordinate of the start point of the second specified line segmenty3
 the Y coordinate of the start point of the second specified line segmentx4
 the X coordinate of the end point of the second specified line segmenty4
 the Y coordinate of the end point of the second specified line segment Returns:
true
if the first specified line segment and the second specified line segment intersect each other;false
otherwise. Since:
 1.2

intersectsLine
public boolean intersectsLine(double x1, double y1, double x2, double y2) Tests if the line segment from(x1,y1)
to(x2,y2)
intersects this line segment. Parameters:
x1
 the X coordinate of the start point of the specified line segmenty1
 the Y coordinate of the start point of the specified line segmentx2
 the X coordinate of the end point of the specified line segmenty2
 the Y coordinate of the end point of the specified line segment Returns:
true
if this line segment and the specified line segment intersect each other;false
otherwise. Since:
 1.2

intersectsLine
Tests if the specified line segment intersects this line segment. Parameters:
l
 the specifiedLine2D
 Returns:
true
if this line segment and the specified line segment intersect each other;false
otherwise. Since:
 1.2

ptSegDistSq
public static double ptSegDistSq(double x1, double y1, double x2, double y2, double px, double py) Returns the square of the distance from a point to a line segment. The distance measured is the distance between the specified point and the closest point between the specified end points. If the specified point intersects the line segment in between the end points, this method returns 0.0. Parameters:
x1
 the X coordinate of the start point of the specified line segmenty1
 the Y coordinate of the start point of the specified line segmentx2
 the X coordinate of the end point of the specified line segmenty2
 the Y coordinate of the end point of the specified line segmentpx
 the X coordinate of the specified point being measured against the specified line segmentpy
 the Y coordinate of the specified point being measured against the specified line segment Returns:
 a double value that is the square of the distance from the specified point to the specified line segment.
 Since:
 1.2
 See Also:

ptSegDist
public static double ptSegDist(double x1, double y1, double x2, double y2, double px, double py) Returns the distance from a point to a line segment. The distance measured is the distance between the specified point and the closest point between the specified end points. If the specified point intersects the line segment in between the end points, this method returns 0.0. Parameters:
x1
 the X coordinate of the start point of the specified line segmenty1
 the Y coordinate of the start point of the specified line segmentx2
 the X coordinate of the end point of the specified line segmenty2
 the Y coordinate of the end point of the specified line segmentpx
 the X coordinate of the specified point being measured against the specified line segmentpy
 the Y coordinate of the specified point being measured against the specified line segment Returns:
 a double value that is the distance from the specified point to the specified line segment.
 Since:
 1.2
 See Also:

ptSegDistSq
public double ptSegDistSq(double px, double py) Returns the square of the distance from a point to this line segment. The distance measured is the distance between the specified point and the closest point between the current line's end points. If the specified point intersects the line segment in between the end points, this method returns 0.0. Parameters:
px
 the X coordinate of the specified point being measured against this line segmentpy
 the Y coordinate of the specified point being measured against this line segment Returns:
 a double value that is the square of the distance from the specified point to the current line segment.
 Since:
 1.2
 See Also:

ptSegDistSq
Returns the square of the distance from aPoint2D
to this line segment. The distance measured is the distance between the specified point and the closest point between the current line's end points. If the specified point intersects the line segment in between the end points, this method returns 0.0. Parameters:
pt
 the specifiedPoint2D
being measured against this line segment. Returns:
 a double value that is the square of the distance from the
specified
Point2D
to the current line segment.  Since:
 1.2
 See Also:

ptSegDist
public double ptSegDist(double px, double py) Returns the distance from a point to this line segment. The distance measured is the distance between the specified point and the closest point between the current line's end points. If the specified point intersects the line segment in between the end points, this method returns 0.0. Parameters:
px
 the X coordinate of the specified point being measured against this line segmentpy
 the Y coordinate of the specified point being measured against this line segment Returns:
 a double value that is the distance from the specified point to the current line segment.
 Since:
 1.2
 See Also:

ptSegDist
Returns the distance from aPoint2D
to this line segment. The distance measured is the distance between the specified point and the closest point between the current line's end points. If the specified point intersects the line segment in between the end points, this method returns 0.0. Parameters:
pt
 the specifiedPoint2D
being measured against this line segment Returns:
 a double value that is the distance from the specified
Point2D
to the current line segment.  Since:
 1.2
 See Also:

ptLineDistSq
public static double ptLineDistSq(double x1, double y1, double x2, double y2, double px, double py) Returns the square of the distance from a point to a line. The distance measured is the distance between the specified point and the closest point on the infinitelyextended line defined by the specified coordinates. If the specified point intersects the line, this method returns 0.0. Parameters:
x1
 the X coordinate of the start point of the specified liney1
 the Y coordinate of the start point of the specified linex2
 the X coordinate of the end point of the specified liney2
 the Y coordinate of the end point of the specified linepx
 the X coordinate of the specified point being measured against the specified linepy
 the Y coordinate of the specified point being measured against the specified line Returns:
 a double value that is the square of the distance from the specified point to the specified line.
 Since:
 1.2
 See Also:

ptLineDist
public static double ptLineDist(double x1, double y1, double x2, double y2, double px, double py) Returns the distance from a point to a line. The distance measured is the distance between the specified point and the closest point on the infinitelyextended line defined by the specified coordinates. If the specified point intersects the line, this method returns 0.0. Parameters:
x1
 the X coordinate of the start point of the specified liney1
 the Y coordinate of the start point of the specified linex2
 the X coordinate of the end point of the specified liney2
 the Y coordinate of the end point of the specified linepx
 the X coordinate of the specified point being measured against the specified linepy
 the Y coordinate of the specified point being measured against the specified line Returns:
 a double value that is the distance from the specified point to the specified line.
 Since:
 1.2
 See Also:

ptLineDistSq
public double ptLineDistSq(double px, double py) Returns the square of the distance from a point to this line. The distance measured is the distance between the specified point and the closest point on the infinitelyextended line defined by thisLine2D
. If the specified point intersects the line, this method returns 0.0. Parameters:
px
 the X coordinate of the specified point being measured against this linepy
 the Y coordinate of the specified point being measured against this line Returns:
 a double value that is the square of the distance from a specified point to the current line.
 Since:
 1.2
 See Also:

ptLineDistSq
Returns the square of the distance from a specifiedPoint2D
to this line. The distance measured is the distance between the specified point and the closest point on the infinitelyextended line defined by thisLine2D
. If the specified point intersects the line, this method returns 0.0. Parameters:
pt
 the specifiedPoint2D
being measured against this line Returns:
 a double value that is the square of the distance from a
specified
Point2D
to the current line.  Since:
 1.2
 See Also:

ptLineDist
public double ptLineDist(double px, double py) Returns the distance from a point to this line. The distance measured is the distance between the specified point and the closest point on the infinitelyextended line defined by thisLine2D
. If the specified point intersects the line, this method returns 0.0. Parameters:
px
 the X coordinate of the specified point being measured against this linepy
 the Y coordinate of the specified point being measured against this line Returns:
 a double value that is the distance from a specified point to the current line.
 Since:
 1.2
 See Also:

ptLineDist
Returns the distance from aPoint2D
to this line. The distance measured is the distance between the specified point and the closest point on the infinitelyextended line defined by thisLine2D
. If the specified point intersects the line, this method returns 0.0. Parameters:
pt
 the specifiedPoint2D
being measured Returns:
 a double value that is the distance from a specified
Point2D
to the current line.  Since:
 1.2
 See Also:

contains
public boolean contains(double x, double y) Tests if a specified coordinate is inside the boundary of thisLine2D
. This method is required to implement theShape
interface, but in the case ofLine2D
objects it always returnsfalse
since a line contains no area. 
contains
Tests if a givenPoint2D
is inside the boundary of thisLine2D
. This method is required to implement theShape
interface, but in the case ofLine2D
objects it always returnsfalse
since a line contains no area. 
intersects
public boolean intersects(double x, double y, double w, double h) Tests if the interior of theShape
intersects the interior of a specified rectangular area. The rectangular area is considered to intersect theShape
if any point is contained in both the interior of theShape
and the specified rectangular area.The
Shape.intersects()
method allows aShape
implementation to conservatively returntrue
when:
there is a high probability that the rectangular area and the
Shape
intersect, but  the calculations to accurately determine this intersection are prohibitively expensive.
Shapes
this method might returntrue
even though the rectangular area does not intersect theShape
. TheArea
class performs more accurate computations of geometric intersection than mostShape
objects and therefore can be used if a more precise answer is required. Specified by:
intersects
in interfaceShape
 Parameters:
x
 the X coordinate of the upperleft corner of the specified rectangular areay
 the Y coordinate of the upperleft corner of the specified rectangular areaw
 the width of the specified rectangular areah
 the height of the specified rectangular area Returns:
true
if the interior of theShape
and the interior of the rectangular area intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;false
otherwise. Since:
 1.2
 See Also:

there is a high probability that the rectangular area and the

intersects
Tests if the interior of theShape
intersects the interior of a specifiedRectangle2D
. TheShape.intersects()
method allows aShape
implementation to conservatively returntrue
when:
there is a high probability that the
Rectangle2D
and theShape
intersect, but  the calculations to accurately determine this intersection are prohibitively expensive.
Shapes
this method might returntrue
even though theRectangle2D
does not intersect theShape
. TheArea
class performs more accurate computations of geometric intersection than mostShape
objects and therefore can be used if a more precise answer is required. Specified by:
intersects
in interfaceShape
 Parameters:
r
 the specifiedRectangle2D
 Returns:
true
if the interior of theShape
and the interior of the specifiedRectangle2D
intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;false
otherwise. Since:
 1.2
 See Also:

there is a high probability that the

contains
public boolean contains(double x, double y, double w, double h) Tests if the interior of thisLine2D
entirely contains the specified set of rectangular coordinates. This method is required to implement theShape
interface, but in the case ofLine2D
objects it always returns false since a line contains no area. Specified by:
contains
in interfaceShape
 Parameters:
x
 the X coordinate of the upperleft corner of the specified rectangular areay
 the Y coordinate of the upperleft corner of the specified rectangular areaw
 the width of the specified rectangular areah
 the height of the specified rectangular area Returns:
false
because aLine2D
contains no area. Since:
 1.2
 See Also:

contains
Tests if the interior of thisLine2D
entirely contains the specifiedRectangle2D
. This method is required to implement theShape
interface, but in the case ofLine2D
objects it always returnsfalse
since a line contains no area. 
getBounds
Returns an integerRectangle
that completely encloses theShape
. Note that there is no guarantee that the returnedRectangle
is the smallest bounding box that encloses theShape
, only that theShape
lies entirely within the indicatedRectangle
. The returnedRectangle
might also fail to completely enclose theShape
if theShape
overflows the limited range of the integer data type. ThegetBounds2D
method generally returns a tighter bounding box due to its greater flexibility in representation.Note that the definition of insideness can lead to situations where points on the defining outline of the
shape
may not be considered contained in the returnedbounds
object, but only in cases where those points are also not considered contained in the originalshape
.If a
point
is inside theshape
according to thecontains(point)
method, then it must be inside the returnedRectangle
bounds object according to thecontains(point)
method of thebounds
. Specifically:shape.contains(x,y)
requiresbounds.contains(x,y)
If a
point
is not inside theshape
, then it might still be contained in thebounds
object:bounds.contains(x,y)
does not implyshape.contains(x,y)

getPathIterator
Returns an iteration object that defines the boundary of thisLine2D
. The iterator for this class is not multithreaded safe, which means that thisLine2D
class does not guarantee that modifications to the geometry of thisLine2D
object do not affect any iterations of that geometry that are already in process. Specified by:
getPathIterator
in interfaceShape
 Parameters:
at
 the specifiedAffineTransform
 Returns:
 a
PathIterator
that defines the boundary of thisLine2D
.  Since:
 1.2

getPathIterator
Returns an iteration object that defines the boundary of this flattenedLine2D
. The iterator for this class is not multithreaded safe, which means that thisLine2D
class does not guarantee that modifications to the geometry of thisLine2D
object do not affect any iterations of that geometry that are already in process. Specified by:
getPathIterator
in interfaceShape
 Parameters:
at
 the specifiedAffineTransform
flatness
 the maximum amount that the control points for a given curve can vary from colinear before a subdivided curve is replaced by a straight line connecting the end points. Since aLine2D
object is always flat, this parameter is ignored. Returns:
 a
PathIterator
that defines the boundary of the flattenedLine2D
 Since:
 1.2

clone
Creates a new object of the same class as this object. Overrides:
clone
in classObject
 Returns:
 a clone of this instance.
 Throws:
OutOfMemoryError
 if there is not enough memory. Since:
 1.2
 See Also:
