Class S2Point
- java.lang.Object
-
- org.apache.commons.math3.geometry.spherical.twod.S2Point
-
public class S2Point extends java.lang.Object implements Point<Sphere2D>
This class represents a point on the 2-sphere.We use the mathematical convention to use the azimuthal angle \( \theta \) in the x-y plane as the first coordinate, and the polar angle \( \varphi \) as the second coordinate (see Spherical Coordinates in MathWorld).
Instances of this class are guaranteed to be immutable.
- Since:
- 3.3
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static S2PointMINUS_I-I (coordinates: \( \theta = \pi, \varphi = \pi/2 \)).static S2PointMINUS_J-J (coordinates: \( \theta = 3\pi/2, \varphi = \pi/2 \)).static S2PointMINUS_K-K (coordinates: \( \theta = any angle, \varphi = \pi \)).static S2PointNaNA vector with all coordinates set to NaN.private doublephiPolar angle \( \varphi \).static S2PointPLUS_I+I (coordinates: \( \theta = 0, \varphi = \pi/2 \)).static S2PointPLUS_J+J (coordinates: \( \theta = \pi/2, \varphi = \pi/2 \))).static S2PointPLUS_K+K (coordinates: \( \theta = any angle, \varphi = 0 \)).private static longserialVersionUIDSerializable UID.private doublethetaAzimuthal angle \( \theta \) in the x-y plane.private Vector3DvectorCorresponding 3D normalized vector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doubledistance(Point<Sphere2D> point)Compute the distance between the instance and another point.static doubledistance(S2Point p1, S2Point p2)Compute the distance (angular separation) between two points.booleanequals(java.lang.Object other)Test for the equality of two points on the 2-sphere.doublegetPhi()Get the polar angle \( \varphi \).SpacegetSpace()Get the space to which the point belongs.doublegetTheta()Get the azimuthal angle \( \theta \) in the x-y plane.Vector3DgetVector()Get the corresponding normalized vector in the 3D euclidean space.inthashCode()Get a hashCode for the 2D vector.booleanisNaN()Returns true if any coordinate of this point is NaN; false otherwiseS2Pointnegate()Get the opposite of the instance.private static Vector3Dvector(double theta, double phi)Build the normalized vector corresponding to spherical coordinates.
-
-
-
Field Detail
-
PLUS_I
public static final S2Point PLUS_I
+I (coordinates: \( \theta = 0, \varphi = \pi/2 \)).
-
PLUS_J
public static final S2Point PLUS_J
+J (coordinates: \( \theta = \pi/2, \varphi = \pi/2 \))).
-
PLUS_K
public static final S2Point PLUS_K
+K (coordinates: \( \theta = any angle, \varphi = 0 \)).
-
MINUS_I
public static final S2Point MINUS_I
-I (coordinates: \( \theta = \pi, \varphi = \pi/2 \)).
-
MINUS_J
public static final S2Point MINUS_J
-J (coordinates: \( \theta = 3\pi/2, \varphi = \pi/2 \)).
-
MINUS_K
public static final S2Point MINUS_K
-K (coordinates: \( \theta = any angle, \varphi = \pi \)).
-
NaN
public static final S2Point NaN
A vector with all coordinates set to NaN.
-
serialVersionUID
private static final long serialVersionUID
Serializable UID.- See Also:
- Constant Field Values
-
theta
private final double theta
Azimuthal angle \( \theta \) in the x-y plane.
-
phi
private final double phi
Polar angle \( \varphi \).
-
vector
private final Vector3D vector
Corresponding 3D normalized vector.
-
-
Constructor Detail
-
S2Point
public S2Point(double theta, double phi) throws OutOfRangeExceptionSimple constructor. Build a vector from its spherical coordinates- Parameters:
theta- azimuthal angle \( \theta \) in the x-y planephi- polar angle \( \varphi \)- Throws:
OutOfRangeException- if \( \varphi \) is not in the [\( 0; \pi \)] range- See Also:
getTheta(),getPhi()
-
S2Point
public S2Point(Vector3D vector) throws MathArithmeticException
Simple constructor. Build a vector from its underlying 3D vector- Parameters:
vector- 3D vector- Throws:
MathArithmeticException- if vector norm is zero
-
S2Point
private S2Point(double theta, double phi, Vector3D vector)Build a point from its internal components.- Parameters:
theta- azimuthal angle \( \theta \) in the x-y planephi- polar angle \( \varphi \)vector- corresponding vector
-
-
Method Detail
-
vector
private static Vector3D vector(double theta, double phi) throws OutOfRangeException
Build the normalized vector corresponding to spherical coordinates.- Parameters:
theta- azimuthal angle \( \theta \) in the x-y planephi- polar angle \( \varphi \)- Returns:
- normalized vector
- Throws:
OutOfRangeException- if \( \varphi \) is not in the [\( 0; \pi \)] range
-
getTheta
public double getTheta()
Get the azimuthal angle \( \theta \) in the x-y plane.- Returns:
- azimuthal angle \( \theta \) in the x-y plane
- See Also:
S2Point(double, double)
-
getPhi
public double getPhi()
Get the polar angle \( \varphi \).- Returns:
- polar angle \( \varphi \)
- See Also:
S2Point(double, double)
-
getVector
public Vector3D getVector()
Get the corresponding normalized vector in the 3D euclidean space.- Returns:
- normalized vector
-
getSpace
public Space getSpace()
Get the space to which the point belongs.
-
isNaN
public boolean isNaN()
Returns true if any coordinate of this point is NaN; false otherwise
-
negate
public S2Point negate()
Get the opposite of the instance.- Returns:
- a new vector which is opposite to the instance
-
distance
public double distance(Point<Sphere2D> point)
Compute the distance between the instance and another point.
-
distance
public static double distance(S2Point p1, S2Point p2)
Compute the distance (angular separation) between two points.- Parameters:
p1- first vectorp2- second vector- Returns:
- the angular separation between p1 and p2
-
equals
public boolean equals(java.lang.Object other)
Test for the equality of two points on the 2-sphere.If all coordinates of two points are exactly the same, and none are
Double.NaN, the two points are considered to be equal.NaNcoordinates are considered to affect globally the vector and be equals to each other - i.e, if either (or all) coordinates of the 2D vector are equal toDouble.NaN, the 2D vector is equal toNaN.- Overrides:
equalsin classjava.lang.Object- Parameters:
other- Object to test for equality to this- Returns:
- true if two points on the 2-sphere objects are equal, false if object is null, not an instance of S2Point, or not equal to this S2Point instance
-
hashCode
public int hashCode()
Get a hashCode for the 2D vector.All NaN values have the same hash code.
- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash code value for this object
-
-