public final class PolarCoordinates extends Object implements 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)
.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other)
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 |
getAzimuth()
Return the azimuth angle in radians.
|
int |
getDimension() |
double |
getRadius()
Return the radius value.
|
int |
hashCode()
Get a hashCode for this set of polar coordinates.
|
boolean |
isFinite() |
boolean |
isInfinite() |
boolean |
isNaN() |
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(String input)
Parse the given string and return a new polar coordinates instance.
|
Vector2D |
toCartesian()
Convert this set of polar coordinates to Cartesian coordinates.
|
static Vector2D |
toCartesian(double radius,
double azimuth)
Convert the given polar coordinates to Cartesian form.
|
String |
toString() |
public double getRadius()
public double getAzimuth()
[0, 2pi)
.public int getDimension()
getDimension
in interface Spatial
public boolean isInfinite()
isInfinite
in interface Spatial
public Vector2D toCartesian()
public int hashCode()
All NaN values have the same hash code.
public boolean equals(Object other)
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 to Double.NaN
, the set as a whole is
considered to equal NaN
.
public static PolarCoordinates of(double radius, double azimuth)
radius
lies in the range [0, +Infinity)
and azimuth
in the range [0, 2pi)
.radius
- Radius value.azimuth
- Azimuth angle in radians.PolarCoordinates
instancepublic static PolarCoordinates fromCartesian(double x, double y)
x
- X coordinate valuey
- Y coordinate valuepublic static PolarCoordinates fromCartesian(Vector2D vec)
vec
- vector containing Cartesian coordinatespublic static Vector2D toCartesian(double radius, double azimuth)
radius
- Radius value.azimuth
- Azimuth angle in radians.public static PolarCoordinates parse(String input)
of(double, double)
method. The expected string
format is the same as that returned by toString()
.input
- the string to parsePolarCoordinates
instanceIllegalArgumentException
- if the string format is invalid.public static double normalizeAzimuth(double azimuth)
[0, 2pi)
.azimuth
- azimuth value in radians[0, 2pi)
.Copyright © 2016–2021 The Apache Software Foundation. All rights reserved.