Class Line2D
- Direct Known Subclasses:
Line2D.Double,Line2D.Float
Line2D represents a line segment in (x,y)
coordinate space. This class, like all of the Java 2D API, uses a default
coordinate system called user space in which the y-axis values
increase downward and x-axis values increase to the right. For more
information on the user space coordinate system, see the
Coordinate Systems section of the Java 2D Programmer's Guide.
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
Nested ClassesModifier and TypeClassDescriptionstatic classA line segment specified with double coordinates.static classA line segment specified with float coordinates. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLine2D()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.booleancontains(double x, double y) Tests if a specified coordinate is inside the boundary of thisLine2D.booleancontains(double x, double y, double w, double h) Tests if the interior of thisLine2Dentirely contains the specified set of rectangular coordinates.booleanTests if a givenPoint2Dis inside the boundary of thisLine2D.booleanTests if the interior of thisLine2Dentirely contains the specifiedRectangle2D.abstract Point2DgetP1()Returns the startPoint2Dof thisLine2D.abstract Point2DgetP2()Returns the endPoint2Dof thisLine2D.abstract doublegetX1()Returns the X coordinate of the start point in double precision.abstract doublegetX2()Returns the X coordinate of the end point in double precision.abstract doublegetY1()Returns the Y coordinate of the start point in double precision.abstract doublegetY2()Returns the Y coordinate of the end point in double precision.booleanintersectsLine(Line2D edge) static booleanlinesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) doubleptLineDist(double px, double py) Returns the distance from a point to this line.static doubleptLineDist(double x1, double y1, double x2, double y2, double px, double py) Returns the distance from a point to a line.doubleptLineDist(Point2D pt) Returns the distance from aPoint2Dto this line.doubleptLineDistSq(double px, double py) Returns the square of the distance from a point to this line.static doubleptLineDistSq(double x1, double y1, double x2, double y2, double px, double py) Returns the square of the distance from a point to a line.doubleptLineDistSq(Point2D pt) Returns the square of the distance from a specifiedPoint2Dto this line.intrelativeCCW(double px, double py) Returns an indicator of where the specified point(px,py)lies with respect to this line segment.static intrelativeCCW(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).abstract voidsetLine(double x1, double y1, double x2, double y2) Sets the location of the end points of thisLine2Dto the specified double coordinates.voidSets the location of the end points of thisLine2Dto the same as those end points of the specifiedLine2D.voidSets the location of the end points of thisLine2Dto the specifiedPoint2Dcoordinates.
-
Constructor Details
-
Line2D
protected Line2D()This is an abstract class that cannot be instantiated directly. Type-specific 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
-
getBounds2D
-
intersectsLine
-
linesIntersect
public static boolean linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) -
getX1
Returns the X coordinate of the start point in double precision.- Returns:
- the X coordinate of the start point of this
Line2Dobject. - Since:
- 1.2
-
getY1
Returns the Y coordinate of the start point in double precision.- Returns:
- the Y coordinate of the start point of this
Line2Dobject. - Since:
- 1.2
-
getP1
Returns the startPoint2Dof thisLine2D.- Returns:
- the start
Point2Dof thisLine2D. - Since:
- 1.2
-
getX2
Returns the X coordinate of the end point in double precision.- Returns:
- the X coordinate of the end point of this
Line2Dobject. - Since:
- 1.2
-
getY2
Returns the Y coordinate of the end point in double precision.- Returns:
- the Y coordinate of the end point of this
Line2Dobject. - Since:
- 1.2
-
getP2
Returns the endPoint2Dof thisLine2D.- Returns:
- the end
Point2Dof thisLine2D. - Since:
- 1.2
-
setLine
Sets the location of the end points of thisLine2Dto 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
Sets the location of the end points of thisLine2Dto the specifiedPoint2Dcoordinates.- Parameters:
p1- the startPoint2Dof the line segmentp2- the endPoint2Dof the line segment- Since:
- 1.2
-
setLine
Sets the location of the end points of thisLine2Dto the same as those end points of the specifiedLine2D.- Parameters:
l- the specifiedLine2D- Since:
- 1.2
-
relativeCCW
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 colinearity 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
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 thisLine2Dpy- 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:
-
ptLineDistSq
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 infinitely-extended 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
-
ptLineDist
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 infinitely-extended 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
-
ptLineDistSq
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 infinitely-extended 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
-
ptLineDistSq
Returns the square of the distance from a specifiedPoint2Dto this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by thisLine2D. If the specified point intersects the line, this method returns 0.0.- Parameters:
pt- the specifiedPoint2Dbeing measured against this line- Returns:
- a double value that is the square of the distance from a
specified
Point2Dto the current line. - Since:
- 1.2
-
ptLineDist
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 infinitely-extended 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
-
ptLineDist
Returns the distance from aPoint2Dto this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by thisLine2D. If the specified point intersects the line, this method returns 0.0.- Parameters:
pt- the specifiedPoint2Dbeing measured- Returns:
- a double value that is the distance from a specified
Point2Dto the current line. - Since:
- 1.2
-
contains
Tests if a specified coordinate is inside the boundary of thisLine2D. This method is required to implement theShapeinterface, but in the case ofLine2Dobjects it always returnsfalsesince a line contains no area.- Parameters:
x- the X coordinate of the specified point to be testedy- the Y coordinate of the specified point to be tested- Returns:
falsebecause aLine2Dcontains no area.- Since:
- 1.2
-
contains
Tests if a givenPoint2Dis inside the boundary of thisLine2D. This method is required to implement theShapeinterface, but in the case ofLine2Dobjects it always returnsfalsesince a line contains no area.- Parameters:
p- the specifiedPoint2Dto be tested- Returns:
falsebecause aLine2Dcontains no area.- Since:
- 1.2
-
contains
Tests if the interior of thisLine2Dentirely contains the specified set of rectangular coordinates. This method is required to implement theShapeinterface, but in the case ofLine2Dobjects it always returns false since a line contains no area.- Parameters:
x- the X coordinate of the upper-left corner of the specified rectangular areay- the Y coordinate of the upper-left corner of the specified rectangular areaw- the width of the specified rectangular areah- the height of the specified rectangular area- Returns:
falsebecause aLine2Dcontains no area.- Since:
- 1.2
-
contains
Tests if the interior of thisLine2Dentirely contains the specifiedRectangle2D. This method is required to implement theShapeinterface, but in the case ofLine2Dobjects it always returnsfalsesince a line contains no area.- Parameters:
r- the specifiedRectangle2Dto be tested- Returns:
falsebecause aLine2Dcontains no area.- Since:
- 1.2
-
clone
Creates a new object of the same class as this object.- Overrides:
clonein classObject- Returns:
- a clone of this instance.
- Throws:
OutOfMemoryError- if there is not enough memory.- Since:
- 1.2
- See Also:
-