public final class PointD
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static PointD |
EMPTY
An empty read-only
PointD . |
double |
x
The x-coordinate of the
PointD . |
double |
y
The y-coordinate of the
PointD . |
Constructor and Description |
---|
PointD()
Creates a
PointD with the coordinate origin. |
PointD(double x,
double y)
Creates a
PointD with the specified Double coordinates. |
Modifier and Type | Method and Description |
---|---|
PointD |
add(PointD point)
Adds the location of the specified
PointD to this instance. |
double |
angle()
Gets the polar angle of the vector represented by the
PointD , in radians. |
double |
angleBetween(PointD vector)
Computes the angle between the vector represented by the
PointD and the specified vector. |
double |
angleBetween(PointD a,
PointD b)
Computes the angle between the vectors from the
PointD to the specified locations. |
double |
crossProductLength(PointD vector)
Computes the length of the cross-product of the vector represented by the
PointD
and the specified vector. |
double |
crossProductLength(PointD a,
PointD b)
Computes the length of the cross-product of the vectors from the
PointD
to the specified locations. |
boolean |
equals(java.lang.Object obj)
Compares the specified
Object to this PointD instance. |
static boolean |
equals(PointD a,
PointD b,
double epsilon)
Compares two
PointD instances for equality, given the specified epsilon. |
static PointD[] |
fromDoubles(double... points)
Converts the specified
Double array to a PointD array. |
static PointD |
fromPolar(double length,
double angle)
Creates a
PointD from the specified polar coordinates. |
int |
hashCode()
Returns a hash code for the
PointD . |
boolean |
isCollinear(PointD a,
PointD b)
Determines if the
PointD is collinear with the specified instances. |
boolean |
isCollinear(PointD a,
PointD b,
double epsilon)
Determines if the
PointD is collinear with the specified instances,
given the specified epsilon. |
double |
length()
Gets the absolute length of the vector represented by the
PointD . |
double |
lengthSquared()
Gets the squared absolute length of the vector represented by the
PointD . |
PointD |
move(PointD target,
double distance)
Moves the
PointD by the specfied distance in the specified direction. |
double |
multiply(PointD vector)
Multiplies the vectors represented by the specified
PointD and this instance. |
PointD |
normalize()
Normalizes the vector represented by the
PointD . |
PointD |
restrict(double minX,
double minY,
double maxX,
double maxY)
Restricts the
PointD to the specified location range. |
PointI |
round()
|
PointD |
subtract(PointD point)
Subtracts the location of the specified
PointD from this instance. |
static double[] |
toDoubles(PointD... points)
Converts the specified
PointD array to a Double array. |
PointI |
toPointI()
|
java.lang.String |
toString()
Returns a
String representation of the PointD . |
public final double x
PointD
.public final double y
PointD
.public static final PointD EMPTY
public double angle()
public double angleBetween(PointD vector)
PointD
and the specified vector.
Returns the result of Math.atan2(double, double)
for the cross-product length and the scalar dot product
of the two vectors. The possible range of values is [-Math.PI
, +Math.PI
].vector
- the PointD
vector to compare with this instancevector
, in that orderjava.lang.NullPointerException
- if vector
is null
public double angleBetween(PointD a, PointD b)
PointD
to the specified locations.
Returns the result of Math.atan2(double, double)
for the cross-product length and the scalar dot product
of the two vectors. The possible range of values is [-Math.PI
, +Math.PI
].public double crossProductLength(PointD vector)
PointD
and the specified vector. The absolute value equals the area of the parallelogram
spanned by the PointD
and the specified vector
. The sign indicates their
spatial relationship, as described in crossProductLength(PointD, PointD)
.vector
- the PointD
vector to multiply with this instanceDouble
value indicating the length of the cross-product
of this instance and the specified vector
, in that orderjava.lang.NullPointerException
- if vector
is null
public double crossProductLength(PointD a, PointD b)
PointD
to the specified locations. The absolute value equals the area of the parallelogram
spanned by the vectors from the PointD
to a
and b
.
The sign indicates their spatial relationship of the two vectors, as follows:
a
and then b
constitutes a right-hand turn, assuming y-coordinates increase upward.a
, and b
are collinear.a
and then b
constitutes a left-hand turn, assuming y-coordinates increase upward.a
- the PointD
location where the first vector endsb
- the PointD
location where the second vector endsDouble
value indicating the length of the cross-product of the vectors
from this instance to a
and from this instance to b
, in that orderjava.lang.NullPointerException
- if a
or b
is null
public static boolean equals(PointD a, PointD b, double epsilon)
PointD
instances for equality, given the specified epsilon.a
- the first PointD
to compareb
- the second PointD
to compareepsilon
- the maximum absolute difference where the corresponding dimensions
of a
and b
are considered equaltrue
if the absolute difference between both corresponding dimensions
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 static PointD[] fromDoubles(double... points)
Double
array to a PointD
array.
The returned array has half as many elements as the specified points
and retains the same coordinate sequence. Expects input suitable for the JavaFX
Polygon
and Polyline
classes.points
- an array containing the x
and y
components of
PointD
instances, stored in alternating index positionsPointD
array created from points
java.lang.IllegalArgumentException
- if points
has an odd number of elementsjava.lang.NullPointerException
- if points
is null
public static PointD fromPolar(double length, double angle)
public boolean isCollinear(PointD a, PointD b)
PointD
is collinear with the specified instances.
Returns true
exactly if crossProductLength(PointD, PointD)
is zero for a
and b
.public boolean isCollinear(PointD a, PointD b, double epsilon)
PointD
is collinear with the specified instances,
given the specified epsilon.
Returns true
exactly if crossProductLength(PointD, PointD)
is no greater than epsilon
for a
and b
.a
- the first PointD
to examineb
- the second PointD
to examineepsilon
- the maximum absolute value at which the result of
crossProductLength(org.kynosarges.tektosyne.geometry.PointD)
should be considered zerotrue
if the PointD
is collinear with a
and b
, else false
java.lang.IllegalArgumentException
- if epsilon
is less than zerojava.lang.NullPointerException
- if a
or b
is null
public double length()
PointD
.
Returns the square root of the sum of the squares of x
and y
.PointD
public double lengthSquared()
PointD
.
Returns the sum of the squares of x
and y
.
Use instead of length()
if you only need the squared value.Double
value that equals the square of length()
public PointD move(PointD target, double distance)
PointD
by the specfied distance in the specified direction.
Moves toward target
if distance
is positive, and away from target
if distance
is negative. Returns the current instance if it equals target
or if distance
is zero.public double multiply(PointD vector)
PointD
and this instance.
Returns the sum of the pairwise products of both instances' x
and y
.
That sum equals lengthSquared()
if the specified vector
equals this instance.vector
- the PointD
to multiply with this instanceDouble
value that represents the scalar dot product
of the specified vector
and this instancejava.lang.NullPointerException
- if vector
is null
public PointD restrict(double minX, double minY, double maxX, double maxY)
PointD
to the specified location range.public PointI round()
PointD
to a PointI
by rounding dimensions to the
nearest Integer
values. Uses Fortran.nint(double)
for rounding.public PointD subtract(PointD point)
PointD
from this instance.public static double[] toDoubles(PointD... points)
PointD
array to a Double
array.
The returned array has twice as many elements as the specified points
and retains the same coordinate sequence. Produces output suitable for the JavaFX
Polygon
and Polyline
classes.public PointI toPointI()
public boolean equals(java.lang.Object obj)
Object
to this PointD
instance.public int hashCode()
PointD
.hashCode
in class java.lang.Object
Integer
hash code for the PointD