public final class LineD
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static LineD |
EMPTY
An empty read-only
LineD . |
PointD |
end
The end point of the
LineD . |
PointD |
start
The start point of the
LineD . |
Constructor and Description |
---|
LineD()
Creates a
LineD that starts and ends at the coordinate origin. |
LineD(double startX,
double startY,
double endX,
double endY)
Creates a
LineD with the specified Double coordinates. |
LineD(PointD start,
PointD end)
|
Modifier and Type | Method and Description |
---|---|
double |
angle()
Gets the angle of the
LineD , in radians. |
double |
distanceSquared(PointD q)
|
static boolean |
equals(LineD a,
LineD b,
double epsilon)
Compares two
LineD instances for equality, given the specified epsilon. |
boolean |
equals(java.lang.Object obj)
Compares the specified
Object to this LineD instance. |
double |
findX(double y)
Finds the x-coordinate for the specified y-coordinate on the
LineD or its infinite extension. |
double |
findY(double x)
Finds the y-coordinate for the specified x-coordinate on the
LineD or its infinite extension. |
static LineD[] |
fromDoubles(double... lines)
Converts the specified
Double array to a LineD array. |
static LineD[] |
fromIndexPoints(PointD[] points,
PointI[] indices)
|
int |
hashCode()
Returns a hash code for the
LineD . |
LineIntersection |
intersect(LineD line)
Finds the intersection between the
LineD and a specified instance,
using exact coordinate comparisons. |
LineIntersection |
intersect(LineD line,
double epsilon)
Finds the intersection between the
LineD and a specified instance,
given the specified epsilon for coordinate comparisons. |
PointD |
intersect(PointD q)
|
double |
inverseSlope()
Gets the inverse slope of the
LineD . |
double |
length()
Gets the absolute length of the
LineD . |
double |
lengthSquared()
Gets the squared absolute length of the
LineD . |
LineLocation |
locate(PointD q)
|
LineLocation |
locate(PointD q,
double epsilon)
|
LineLocation |
locateCollinear(PointD q)
|
LineLocation |
locateCollinear(PointD q,
double epsilon)
|
LineD |
reverse()
Reverses the direction of the
LineD . |
LineI |
round()
|
double |
slope()
Gets the slope of the
LineD . |
static double[] |
toDoubles(LineD... lines)
Converts the specified
LineD array to a Double array. |
LineI |
toLineI()
|
java.lang.String |
toString()
Returns a
String representation of the LineD . |
PointD |
vector()
Gets the vector defined by the
LineD . |
public static final LineD EMPTY
public LineD()
LineD
that starts and ends at the coordinate origin.
Both start
and end
are set to PointD.EMPTY
.public LineD(double startX, double startY, double endX, double endY)
LineD
with the specified Double
coordinates.public double angle()
LineD
, in radians.
Returns the result of Math.atan2(double, double)
for the vertical and horizontal distances between
end
and start
, within the interval [-Math.PI
, +Math.PI
].
angle()
equals zero if the LineD
extends horizontally to the right,
and increases as the line turns clockwise (y-axis pointing down) or counter-clockwise
(y-axis pointing up).
public double distanceSquared(PointD q)
public static boolean equals(LineD a, LineD b, double epsilon)
LineD
instances for equality, given the specified epsilon.a
- the first LineD
to compareb
- the second LineD
to compareepsilon
- the maximum absolute difference where the corresponding coordinates
of a
and b
are considered equaltrue
if the absolute difference between all corresponding coordinates
of a
and b
is no greater than epsilon
, else false
java.lang.IllegalArgumentException
- if epsilon
is less than zerojava.lang.NullPointerException
- if a
or b
is null
public double findX(double y)
public double findY(double x)
public static LineD[] fromDoubles(double... lines)
Double
array to a LineD
array.
The returned array has a quarter as many elements as the specified
lines
and retains the same coordinate sequence.lines
- an array containing the coordinates start.x, start.y, end.x, end.y
of
LineD
instances, stored in successive index positions per LineD
LineD
array created from lines
java.lang.IllegalArgumentException
- if the length of lines
is not divisible by fourjava.lang.NullPointerException
- if lines
is null
public static LineD[] fromIndexPoints(PointD[] points, PointI[] indices)
PointD
coordinates and zero-based indices
into an array of equivalent LineD
instances.points
- an array of PointD
coordinates representing start
or end
pointsindices
- an array of PointI
pairs of zero-based indices within points
LineD
instances created from the pairs of points
coordinates indexed by each indices
elementjava.lang.ArrayIndexOutOfBoundsException
- if indices
contains an index that is less than zero,
or equal to or greater than the number of points
elementsjava.lang.NullPointerException
- if points
or indices
is null
or contains any null
elementspublic LineIntersection intersect(LineD line)
LineD
and a specified instance,
using exact coordinate comparisons.
Returns the result of LineIntersection.find(org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD)
for the start
and
end
points of this instance and the specified line
, in that order.line
- the LineD
to intersect with this instanceLineIntersection
that describes if and how this instance
intersects the specified line
java.lang.NullPointerException
- if line
is null
public LineIntersection intersect(LineD line, double epsilon)
LineD
and a specified instance,
given the specified epsilon for coordinate comparisons.
Returns the result of LineIntersection.find(org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD)
for the start
and
end
points of this instance and the specified line
, in that order,
and for the specified epsilon
.line
- the LineD
to intersect with this instanceepsilon
- the maximum absolute difference at which coordinates and intermediate results
should be considered equal. Always raised to a minium of 1e-10.LineIntersection
that describes if and how this instance
intersects the specified line
java.lang.NullPointerException
- if line
is null
public double inverseSlope()
public double length()
LineD
.
Returns the square root of the sum of the squares of the horizontal
and vertical extensions of the LineD
.LineD
public double lengthSquared()
LineD
.
Returns the sum of the squares of the horizontal and vertical extensions of the
LineD
. Use instead of length()
if you only need the squared value.Double
value that equals the square of length()
public LineLocation locate(PointD q)
PointD
relative to the LineD
,
using exact coordinate comparisons.
Never returns null
. The return values LineLocation.LEFT
and
LineLocation.RIGHT
assume that y-coordinates increase upward.
locate
is based on the classify
algorithm by Michael J. Laszlo,
Computational Geometry and Computer Graphics in C++, Prentice Hall 1996, p.76.
q
- the PointD
coordinates to examineLineLocation
value indicating the location of q
relative to the LineD
java.lang.NullPointerException
- if q
is null
public LineLocation locate(PointD q, double epsilon)
PointD
relative to the LineD
,
given the specified epsilon for coordinate comparisons.
Never returns null
. The return values LineLocation.LEFT
and
LineLocation.RIGHT
assume that y-coordinates increase upward.q
- the PointD
coordinates to examineepsilon
- the maximum absolute difference at which coordinates
and intermediate results should be considered equalLineLocation
value indicating the location of q
relative to the LineD
java.lang.IllegalArgumentException
- if epsilon
is less than zerojava.lang.NullPointerException
- if q
is null
public LineLocation locateCollinear(PointD q)
PointD
relative to the LineD
,
assuming they are collinear and using exact coordinate comparisons.
Returns the result of LineIntersection.locateCollinear(org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD)
for the start
and end
points of this instance and the specified q
, in that order.
Never returns null
, LineLocation.LEFT
, or LineLocation.RIGHT
due to the assumption of collinearity.q
- the PointD
coordinates to examineLineLocation
value indicating the location of q
relative to the LineD
java.lang.NullPointerException
- if q
is null
public LineLocation locateCollinear(PointD q, double epsilon)
PointD
relative to the LineD
,
assuming they are collinear and given the specified epsilon for coordinate comparisons.
Returns the result of LineIntersection.locateCollinear(org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD)
for the start
and end
points of this instance and the specified q
and epsilon
,
in that order. Never returns null
, LineLocation.LEFT
, or
LineLocation.RIGHT
due to the assumption of collinearity.q
- the PointD
coordinates to examineepsilon
- the maximum absolute difference at which coordinates
and intermediate results should be considered equalLineLocation
value indicating the location of q
relative to the LineD
java.lang.IllegalArgumentException
- if epsilon
is less than zerojava.lang.NullPointerException
- if q
is null
public LineI round()
LineD
to a LineI
by rounding coordinates to the
nearest Integer
values. Uses PointD.round()
for rounding.LineI
whose LineI.start
and LineI.end
points equal the corresponding points of the LineD
, with
each coordinate rounded to the nearest Integer
valuejava.lang.ArithmeticException
- if any coordinate overflows Integer
public double slope()
LineD
.
Equals 1/inverseSlope()
. May return a negative value, depending on angle()
.public static double[] toDoubles(LineD... lines)
LineD
array to a Double
array.
The returned array has four times as many elements as the specified
lines
and retains the same coordinate sequence.public LineI toLineI()
LineD
to a LineI
by truncating coordinates to the
nearest Integer
values. Uses Integer
casts for truncation.LineI
whose LineI.start
and LineI.end
points equal the corresponding points of the LineD
, with
each coordinate truncated to the nearest Integer
valuejava.lang.ArithmeticException
- if any coordinate overflows Integer
public PointD vector()
public boolean equals(java.lang.Object obj)
Object
to this LineD
instance.public int hashCode()
LineD
.hashCode
in class java.lang.Object
Integer
hash code for the LineD