Class Point2S
Instances of this class are guaranteed to be immutable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double
Azimuthal angle in the x-y plane.static final Point2S
-I (coordinates: ( azimuth = pi, polar = pi/2 )).static final Point2S
-J (coordinates: ( azimuth = 3pi/2, polar = pi/2 )).static final Point2S
-K (coordinates: ( azimuth = any angle, polar = pi )).static final Point2S
A point with all coordinates set to NaN.static final Point2S
+I (coordinates: ( azimuth = 0, polar = pi/2 )).static final Point2S
+J (coordinates: ( azimuth = pi/2, polar = pi/2 ))).static final Point2S
+K (coordinates: ( azimuth = any angle, polar = 0 )).private final double
Polar angle.static final Comparator
<Point2S> Comparator that sorts points in component-wise ascending order, first sorting by polar value and then by azimuth value.private final Vector3D.Unit
Corresponding 3D normalized vector. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Point2S
(double azimuth, double polar, Vector3D.Unit vector) Build a point from its internal components. -
Method Summary
Modifier and TypeMethodDescriptionGet the point exactly opposite this point on the sphere.private static Vector3D.Unit
computeVector
(double azimuth, double polar) Compute the 3D Euclidean vector associated with the given spherical coordinates.double
Compute the distance between this point and another point.static double
Compute the distance (angular separation) between two points.boolean
Return true if this point should be considered equivalent to the argument using the given precision context.boolean
Test for the equality of two points.static Point2S
Build a point from its underlying 3D vector.double
Get the azimuth angle in the x-y plane in the range[0, 2pi)
.int
Returns the number of dimensions in the space that this element belongs to.double
getPolar()
Get the polar angle in the range[0, pi)
.Get the corresponding normalized vector in 3D Euclidean space.int
hashCode()
Get a hashCode for the point.boolean
isFinite()
Returns true if all values in this element are finite, meaning they are not NaN or infinite.boolean
Returns true if any value in this element is infinite and none are NaN; otherwise, returns false.boolean
isNaN()
Returns true if any value in this element is NaN; otherwise returns false.static Point2S
of
(double azimuth, double polar) Build a vector from its spherical coordinates.static Point2S
Parses the given string and returns a new point instance.Spherically interpolate a point along the shortest arc between this point and the given point.toString()
-
Field Details
-
PLUS_I
+I (coordinates: ( azimuth = 0, polar = pi/2 )). -
PLUS_J
+J (coordinates: ( azimuth = pi/2, polar = pi/2 ))). -
PLUS_K
+K (coordinates: ( azimuth = any angle, polar = 0 )). -
MINUS_I
-I (coordinates: ( azimuth = pi, polar = pi/2 )). -
MINUS_J
-J (coordinates: ( azimuth = 3pi/2, polar = pi/2 )). -
MINUS_K
-K (coordinates: ( azimuth = any angle, polar = pi )). -
NaN
A point with all coordinates set to NaN. -
POLAR_AZIMUTH_ASCENDING_ORDER
Comparator that sorts points in component-wise ascending order, first sorting by polar value and then by azimuth value. Points are only considered equal if their components match exactly. Null arguments are evaluated as being greater than non-null arguments. -
azimuth
private final double azimuthAzimuthal angle in the x-y plane. -
polar
private final double polarPolar angle. -
vector
Corresponding 3D normalized vector.
-
-
Constructor Details
-
Point2S
Build a point from its internal components.- Parameters:
azimuth
- azimuthal angle in the x-y planepolar
- polar anglevector
- corresponding vector; if null, the vector is computed
-
-
Method Details
-
getAzimuth
public double getAzimuth()Get the azimuth angle in the x-y plane in the range[0, 2pi)
.- Returns:
- azimuth angle in the x-y plane in the range
[0, 2pi)
. - See Also:
-
getPolar
public double getPolar()Get the polar angle in the range[0, pi)
.- Returns:
- polar angle in the range
[0, pi)
. - See Also:
-
getVector
Get the corresponding normalized vector in 3D Euclidean space. This value will be null if the spherical coordinates of the point are infinite or NaN.- Returns:
- normalized vector
-
getDimension
public int getDimension()Returns the number of dimensions in the space that this element belongs to.- Specified by:
getDimension
in interfaceSpatial
- Returns:
- the number of dimensions in the element's space
-
isNaN
public boolean isNaN()Returns true if any value in this element is NaN; otherwise returns false. -
isInfinite
public boolean isInfinite()Returns true if any value in this element is infinite and none are NaN; otherwise, returns false.- Specified by:
isInfinite
in interfaceSpatial
- Returns:
- true if any value in this element is infinite and none are NaN
-
isFinite
public boolean isFinite()Returns true if all values in this element are finite, meaning they are not NaN or infinite. -
antipodal
Get the point exactly opposite this point on the sphere. The returned point ispi
distance away from the current instance.- Returns:
- the point exactly opposite this point on the sphere
-
distance
Compute the distance between this point and another point. -
slerp
Spherically interpolate a point along the shortest arc between this point and the given point. The parametert
controls the interpolation and is expected to be in the range[0, 1]
, with0
returning a point equivalent to the current instance1
returning a point equivalent to the given instance. If the points are antipodal, then an arbitrary arc is chosen from the infinite number available.- Parameters:
other
- other point to interpolate witht
- interpolation parameter- Returns:
- spherically interpolated point
- See Also:
-
eq
public boolean eq(Point2S point, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Return true if this point should be considered equivalent to the argument using the given precision context. This will be true if the distance between the points is equivalent to zero as evaluated by the precision context.- Parameters:
point
- point to compare withprecision
- precision context used to perform floating point comparisons- Returns:
- true if this point should be considered equivalent to the argument using the given precision context
-
hashCode
public int hashCode()Get a hashCode for the point. .All NaN values have the same hash code.
-
equals
Test for the equality of two points.If all spherical coordinates of two points are exactly the same, and none are
Double.NaN
, the two points are considered to be equal. Note that the comparison is made using the azimuth and polar coordinates only; the corresponding 3D vectors are not compared. This is significant at the poles, where an infinite number of points share the same underlying 3D vector but may have different spherical coordinates. For example, the points(0, 0)
and(1, 0)
(both located at a pole but with different azimuths) will not be considered equal by this method, even though they share the exact same underlying 3D vector.NaN
coordinates are considered to affect the point globally and be equals to each other - i.e, if either (or all) coordinates of the point are equal toDouble.NaN
, the point is equal toNaN
. -
toString
-
of
Build a vector from its spherical coordinates.- Parameters:
azimuth
- azimuthal angle in the x-y planepolar
- polar angle- Returns:
- point instance with the given coordinates
- See Also:
-
from
Build a point from its underlying 3D vector.- Parameters:
vector
- 3D vector- Returns:
- point instance with the coordinates determined by the given 3D vector
- Throws:
IllegalStateException
- if vector norm is zero
-
parse
Parses the given string and returns a new point instance. The expected string format is the same as that returned bytoString()
.- Parameters:
str
- the string to parse- Returns:
- point instance represented by the string
- Throws:
IllegalArgumentException
- if the given string has an invalid format
-
distance
Compute the distance (angular separation) between two points.- Parameters:
p1
- first vectorp2
- second vector- Returns:
- the angular separation between p1 and p2
-
computeVector
Compute the 3D Euclidean vector associated with the given spherical coordinates. Null is returned if the coordinates are infinite or NaN.- Parameters:
azimuth
- azimuth valuepolar
- polar value- Returns:
- the 3D Euclidean vector associated with the given spherical coordinates or null if either of the arguments are infinite or NaN.
-