APIdia Launch Partner
Top Description Inners Constructors Methods
java.awt.geom

public abstract Class Line2D

extends Object
implements Shape, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.awt.Shape
Known Direct Subclasses
java.awt.geom.Line2D.Float, java.awt.geom.Line2D.Double
Imports
java.awt.Rectangle, .Shape, java.io.Serial, .Serializable

This 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.

Author
Jim Graham
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Line2D.Double

A line segment specified with double coordinates.

public static class
Line2D.Float

A line segment specified with float coordinates.

Constructor Summary

AccessConstructor and Description
protected
Line2D()

This is an abstract class that cannot be instantiated directly.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

a clone of this instance.
clone
()

Overrides java.lang.Object.clone.

Creates a new object of the same class as this object.

public boolean

Returns:

false because a Line2D contains no area.
contains
(double
the X coordinate of the specified point to be tested
x
,
double
the Y coordinate of the specified point to be tested
y
)

Implements java.awt.Shape.contains.

Tests if a specified coordinate is inside the boundary of this Line2D.

public boolean

Returns:

false because a Line2D contains no area.
contains
(Point2D
the specified Point2D to be tested
p
)

Implements java.awt.Shape.contains.

Tests if a given Point2D is inside the boundary of this Line2D.

public boolean

Returns:

false because a Line2D contains no area.
contains
(double
the X coordinate of the upper-left corner of the specified rectangular area
x
,
double
the Y coordinate of the upper-left corner of the specified rectangular area
y
,
double
the width of the specified rectangular area
w
,
double
the height of the specified rectangular area
h
)

Implements java.awt.Shape.contains.

Tests if the interior of this Line2D entirely contains the specified set of rectangular coordinates.

public boolean

Returns:

false because a Line2D contains no area.
contains
(Rectangle2D
the specified Rectangle2D to be tested
r
)

Implements java.awt.Shape.contains.

Tests if the interior of this Line2D entirely contains the specified Rectangle2D.

public Rectangle
getBounds()

Implements java.awt.Shape.getBounds.

Returns an integer Rectangle that completely encloses the Shape.

public abstract Point2D

Returns:

the start Point2D of this Line2D.
getP1
()

Returns the start Point2D of this Line2D.

public abstract Point2D

Returns:

the end Point2D of this Line2D.
getP2
()

Returns the end Point2D of this Line2D.

public PathIterator

Returns:

a PathIterator that defines the boundary of this Line2D.
getPathIterator
(AffineTransform
the specified AffineTransform
at
)

Implements java.awt.Shape.getPathIterator.

Returns an iteration object that defines the boundary of this Line2D.

public PathIterator

Returns:

a PathIterator that defines the boundary of the flattened Line2D
getPathIterator
(AffineTransform
the specified AffineTransform
at
,
double
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 a Line2D object is always flat, this parameter is ignored.
flatness
)

Implements java.awt.Shape.getPathIterator.

Returns an iteration object that defines the boundary of this flattened Line2D.

public abstract double

Returns:

the X coordinate of the start point of this Line2D object.
getX1
()

Returns the X coordinate of the start point in double precision.

public abstract double

Returns:

the X coordinate of the end point of this Line2D object.
getX2
()

Returns the X coordinate of the end point in double precision.

public abstract double

Returns:

the Y coordinate of the start point of this Line2D object.
getY1
()

Returns the Y coordinate of the start point in double precision.

public abstract double

Returns:

the Y coordinate of the end point of this Line2D object.
getY2
()

Returns the Y coordinate of the end point in double precision.

public boolean
intersects(double x, double y, double w, double h)

Implements java.awt.Shape.intersects.

Tests if the interior of the Shape intersects the interior of a specified rectangular area.

public boolean
intersects(Rectangle2D r)

Implements java.awt.Shape.intersects.

Tests if the interior of the Shape intersects the interior of a specified Rectangle2D.

public boolean

Returns:

true if this line segment and the specified line segment intersect each other; false otherwise.
intersectsLine
(double
the X coordinate of the start point of the specified line segment
x1
,
double
the Y coordinate of the start point of the specified line segment
y1
,
double
the X coordinate of the end point of the specified line segment
x2
,
double
the Y coordinate of the end point of the specified line segment
y2
)

Tests if the line segment from (x1,y1) to (x2,y2) intersects this line segment.

public boolean

Returns:

true if this line segment and the specified line segment intersect each other; false otherwise.
intersectsLine
(Line2D
the specified Line2D
l
)

Tests if the specified line segment intersects this line segment.

public static boolean

Returns:

true if the first specified line segment and the second specified line segment intersect each other; false otherwise.
linesIntersect
(double
the X coordinate of the start point of the first specified line segment
x1
,
double
the Y coordinate of the start point of the first specified line segment
y1
,
double
the X coordinate of the end point of the first specified line segment
x2
,
double
the Y coordinate of the end point of the first specified line segment
y2
,
double
the X coordinate of the start point of the second specified line segment
x3
,
double
the Y coordinate of the start point of the second specified line segment
y3
,
double
the X coordinate of the end point of the second specified line segment
x4
,
double
the Y coordinate of the end point of the second specified line segment
y4
)

Tests if the line segment from (x1,y1) to (x2,y2) intersects the line segment from (x3,y3) to (x4,y4).

public static double

Returns:

a double value that is the distance from the specified point to the specified line.
ptLineDist
(double
the X coordinate of the start point of the specified line
x1
,
double
the Y coordinate of the start point of the specified line
y1
,
double
the X coordinate of the end point of the specified line
x2
,
double
the Y coordinate of the end point of the specified line
y2
,
double
the X coordinate of the specified point being measured against the specified line
px
,
double
the Y coordinate of the specified point being measured against the specified line
py
)

Returns the distance from a point to a line.

public double

Returns:

a double value that is the distance from a specified point to the current line.
ptLineDist
(double
the X coordinate of the specified point being measured against this line
px
,
double
the Y coordinate of the specified point being measured against this line
py
)

Returns the distance from a point to this line.

public double

Returns:

a double value that is the distance from a specified Point2D to the current line.
ptLineDist
(Point2D
the specified Point2D being measured
pt
)

Returns the distance from a Point2D to this line.

public static double

Returns:

a double value that is the square of the distance from the specified point to the specified line.
ptLineDistSq
(double
the X coordinate of the start point of the specified line
x1
,
double
the Y coordinate of the start point of the specified line
y1
,
double
the X coordinate of the end point of the specified line
x2
,
double
the Y coordinate of the end point of the specified line
y2
,
double
the X coordinate of the specified point being measured against the specified line
px
,
double
the Y coordinate of the specified point being measured against the specified line
py
)

Returns the square of the distance from a point to a line.

public double

Returns:

a double value that is the square of the distance from a specified point to the current line.
ptLineDistSq
(double
the X coordinate of the specified point being measured against this line
px
,
double
the Y coordinate of the specified point being measured against this line
py
)

Returns the square of the distance from a point to this line.

public double

Returns:

a double value that is the square of the distance from a specified Point2D to the current line.
ptLineDistSq
(Point2D
the specified Point2D being measured against this line
pt
)

Returns the square of the distance from a specified Point2D to this line.

public static double

Returns:

a double value that is the distance from the specified point to the specified line segment.
ptSegDist
(double
the X coordinate of the start point of the specified line segment
x1
,
double
the Y coordinate of the start point of the specified line segment
y1
,
double
the X coordinate of the end point of the specified line segment
x2
,
double
the Y coordinate of the end point of the specified line segment
y2
,
double
the X coordinate of the specified point being measured against the specified line segment
px
,
double
the Y coordinate of the specified point being measured against the specified line segment
py
)

Returns the distance from a point to a line segment.

public double

Returns:

a double value that is the distance from the specified point to the current line segment.
ptSegDist
(double
the X coordinate of the specified point being measured against this line segment
px
,
double
the Y coordinate of the specified point being measured against this line segment
py
)

Returns the distance from a point to this line segment.

public double

Returns:

a double value that is the distance from the specified Point2D to the current line segment.
ptSegDist
(Point2D
the specified Point2D being measured against this line segment
pt
)

Returns the distance from a Point2D to this line segment.

public static double

Returns:

a double value that is the square of the distance from the specified point to the specified line segment.
ptSegDistSq
(double
the X coordinate of the start point of the specified line segment
x1
,
double
the Y coordinate of the start point of the specified line segment
y1
,
double
the X coordinate of the end point of the specified line segment
x2
,
double
the Y coordinate of the end point of the specified line segment
y2
,
double
the X coordinate of the specified point being measured against the specified line segment
px
,
double
the Y coordinate of the specified point being measured against the specified line segment
py
)

Returns the square of the distance from a point to a line segment.

public double

Returns:

a double value that is the square of the distance from the specified point to the current line segment.
ptSegDistSq
(double
the X coordinate of the specified point being measured against this line segment
px
,
double
the Y coordinate of the specified point being measured against this line segment
py
)

Returns the square of the distance from a point to this line segment.

public double

Returns:

a double value that is the square of the distance from the specified Point2D to the current line segment.
ptSegDistSq
(Point2D
the specified Point2D being measured against this line segment.
pt
)

Returns the square of the distance from a Point2D to this line segment.

public static int

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.
relativeCCW
(double
the X coordinate of the start point of the specified line segment
x1
,
double
the Y coordinate of the start point of the specified line segment
y1
,
double
the X coordinate of the end point of the specified line segment
x2
,
double
the Y coordinate of the end point of the specified line segment
y2
,
double
the X coordinate of the specified point to be compared with the specified line segment
px
,
double
the Y coordinate of the specified point to be compared with the specified line segment
py
)

Returns an indicator of where the specified point (px,py) lies with respect to the line segment from (x1,y1) to (x2,y2).

public int

Returns:

an integer that indicates the position of the specified coordinates with respect to this Line2D
relativeCCW
(double
the X coordinate of the specified point to be compared with this Line2D
px
,
double
the Y coordinate of the specified point to be compared with this Line2D
py
)

Returns an indicator of where the specified point (px,py) lies with respect to this line segment.

public int

Returns:

an integer that indicates the position of the specified Point2D with respect to this Line2D
relativeCCW
(Point2D
the specified Point2D to be compared with this Line2D
p
)

Returns an indicator of where the specified Point2D lies with respect to this line segment.

public abstract void
setLine(double
the X coordinate of the start point
x1
,
double
the Y coordinate of the start point
y1
,
double
the X coordinate of the end point
x2
,
double
the Y coordinate of the end point
y2
)

Sets the location of the end points of this Line2D to the specified double coordinates.

public void
setLine(Point2D
the start Point2D of the line segment
p1
,
Point2D
the end Point2D of the line segment
p2
)

Sets the location of the end points of this Line2D to the specified Point2D coordinates.

public void
setLine(Line2D
the specified Line2D
l
)

Sets the location of the end points of this Line2D to the same as those end points of the specified Line2D.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait