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
ConstructorsModifierConstructorDescriptionprivatePolarCoordinates(double radius, double azimuth) Simple constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTest for the equality of two sets of polar coordinates.static PolarCoordinatesfromCartesian(double x, double y) Convert the given Cartesian coordinates to polar form.static PolarCoordinatesfromCartesian(Vector2D vec) Convert the given Cartesian coordinates to polar form.doubleReturn the azimuth angle in radians.intReturns the number of dimensions in the space that this element belongs to.doubleReturn the radius value.inthashCode()Get a hashCode for this set of polar coordinates.booleanisFinite()Returns true if all values in this element are finite, meaning they are not NaN or infinite.booleanReturns true if any value in this element is infinite and none are NaN; otherwise, returns false.booleanisNaN()Returns true if any value in this element is NaN; otherwise returns false.static doublenormalizeAzimuth(double azimuth) Normalize an azimuth value to be within the range[0, 2pi).static PolarCoordinatesof(double radius, double azimuth) Return a new instance with the given polar coordinate values.static PolarCoordinatesParse the given string and return a new polar coordinates instance.Convert this set of polar coordinates to Cartesian coordinates.static Vector2DtoCartesian(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:
getDimensionin interfaceSpatial- Returns:
- the number of dimensions in the element's space
-
isNaN
-
isInfinite
public boolean isInfinite()Returns true if any value in this element is infinite and none are NaN; otherwise, returns false.- Specified by:
isInfinitein interfaceSpatial- Returns:
- true if any value in this element is infinite and none are NaN
-
isFinite
-
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
-
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.NaNvalues 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 thatradiuslies in the range[0, +Infinity)andazimuthin the range[0, 2pi).- Parameters:
radius- Radius value.azimuth- Azimuth angle in radians.- Returns:
- new
PolarCoordinatesinstance
-
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
PolarCoordinatesinstance - 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).
-