Class PolarCoordinates
- All Implemented Interfaces:
Spatial
Polar coordinates are defined by a distance from a reference point and an angle from a reference direction. The distance value is called the radial coordinate, or radius, and the angle is called the angular coordinate, or azimuth. This class follows the standard mathematical convention of using the positive x-axis as the reference direction and measuring positive angles counter-clockwise, toward the positive y-axis. The origin is used as the reference point. Polar coordinate are related to Cartesian coordinates as follows:
x = r * cos(θ) y = r * sin(θ) r = √(x^2 + y^2) θ = atan2(y, x)where r is the radius and θ is the azimuth of the polar coordinates.
In order to ensure the uniqueness of coordinate sets, coordinate values
are normalized so that radius
is in the range [0, +Infinity)
and azimuth
is in the range [0, 2pi)
.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
PolarCoordinates
(double radius, double azimuth) Simple constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Test for the equality of two sets of polar coordinates.static PolarCoordinates
fromCartesian
(double x, double y) Convert the given Cartesian coordinates to polar form.static PolarCoordinates
fromCartesian
(Vector2D vec) Convert the given Cartesian coordinates to polar form.double
Return the azimuth angle in radians.int
Returns the number of dimensions in the space that this element belongs to.double
Return the radius value.int
hashCode()
Get a hashCode for this set of polar coordinates.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 double
normalizeAzimuth
(double azimuth) Normalize an azimuth value to be within the range[0, 2pi)
.static PolarCoordinates
of
(double radius, double azimuth) Return a new instance with the given polar coordinate values.static PolarCoordinates
Parse the given string and return a new polar coordinates instance.Convert this set of polar coordinates to Cartesian coordinates.static Vector2D
toCartesian
(double radius, double azimuth) Convert the given polar coordinates to Cartesian form.toString()
-
Field Details
-
radius
private final double radiusRadius value. -
azimuth
private final double azimuthAzimuth angle in radians.
-
-
Constructor Details
-
PolarCoordinates
private PolarCoordinates(double radius, double azimuth) Simple constructor. Input values are normalized.- Parameters:
radius
- Radius value.azimuth
- Azimuth angle in radians.
-
-
Method Details
-
getRadius
public double getRadius()Return the radius value. The value will be greater than or equal to 0.- Returns:
- radius value
-
getAzimuth
public double getAzimuth()Return the azimuth angle in radians. The value will be in the range[0, 2pi)
.- Returns:
- azimuth value in radians.
-
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. -
toCartesian
Convert this set of polar coordinates to Cartesian coordinates.- Returns:
- A 2-dimensional vector with an equivalent set of coordinates in Cartesian form
-
hashCode
public int hashCode()Get a hashCode for this set of polar coordinates.All NaN values have the same hash code.
-
equals
Test for the equality of two sets of polar coordinates.If all values of two sets of coordinates are exactly the same, and none are
Double.NaN
, the two sets are considered to be equal.NaN
values are considered to globally affect the coordinates and be equal to each other - i.e, if either (or all) values of the coordinate set are equal toDouble.NaN
, the set as a whole is considered to equalNaN
. -
toString
-
of
Return a new instance with the given polar coordinate values. The values are normalized so thatradius
lies in the range[0, +Infinity)
andazimuth
in the range[0, 2pi)
.- Parameters:
radius
- Radius value.azimuth
- Azimuth angle in radians.- Returns:
- new
PolarCoordinates
instance
-
fromCartesian
Convert the given Cartesian coordinates to polar form.- Parameters:
x
- X coordinate valuey
- Y coordinate value- Returns:
- polar coordinates equivalent to the given Cartesian coordinates
-
fromCartesian
Convert the given Cartesian coordinates to polar form.- Parameters:
vec
- vector containing Cartesian coordinates- Returns:
- polar coordinates equivalent to the given Cartesian coordinates
-
toCartesian
Convert the given polar coordinates to Cartesian form.- Parameters:
radius
- Radius value.azimuth
- Azimuth angle in radians.- Returns:
- A 2-dimensional vector with an equivalent set of coordinates in Cartesian form
-
parse
Parse the given string and return a new polar coordinates instance. The parsed coordinates are normalized as in theof(double, double)
method. The expected string format is the same as that returned bytoString()
.- Parameters:
input
- the string to parse- Returns:
- new
PolarCoordinates
instance - Throws:
IllegalArgumentException
- if the string format is invalid.
-
normalizeAzimuth
public static double normalizeAzimuth(double azimuth) Normalize an azimuth value to be within the range[0, 2pi)
.- Parameters:
azimuth
- azimuth value in radians- Returns:
- equivalent azimuth value in the range
[0, 2pi)
.
-