org.apache.commons.math3.geometry.euclidean.threed

## Class SphericalCoordinates

• java.lang.Object
• org.apache.commons.math3.geometry.euclidean.threed.SphericalCoordinates
• All Implemented Interfaces:
Serializable

public class SphericalCoordinates
extends Object
implements Serializable
This class provides conversions related to spherical coordinates.

The conventions used here are the mathematical ones, i.e. spherical coordinates are related to Cartesian coordinates as follows:

• x = r cos(θ) sin(Φ)
• y = r sin(θ) sin(Φ)
• z = r cos(Φ)
• r = √(x2+y2+z2)
• θ = atan2(y, x)
• Φ = acos(z/r)

r is the radius, θ is the azimuthal angle in the x-y plane and Φ is the polar (co-latitude) angle. These conventions are different from the conventions used in physics (and in particular in spherical harmonics) where the meanings of θ and Φ are reversed.

This class provides conversion of coordinates and also of gradient and Hessian between spherical and Cartesian coordinates.

Since:
3.2
Version:
$Id: SphericalCoordinates.html 885258 2013-11-03 02:46:49Z tn$
Serialized Form
• ### Constructor Summary

Constructors
Constructor and Description
SphericalCoordinates(double r, double theta, double phi)
Build a spherical coordinates transformer from spherical coordinates.
SphericalCoordinates(Vector3D v)
Build a spherical coordinates transformer from Cartesian coordinates.
• ### Method Summary

Methods
Modifier and Type Method and Description
Vector3D getCartesian()
Get the Cartesian coordinates.
double getPhi()
Get the polar (co-latitude) angle.
double getR()
double getTheta()
Get the azimuthal angle in x-y plane.
Convert a gradient with respect to spherical coordinates into a gradient with respect to Cartesian coordinates.
Convert a Hessian with respect to spherical coordinates into a Hessian with respect to Cartesian coordinates.
• ### Constructor Detail

• #### SphericalCoordinates

public SphericalCoordinates(Vector3D v)
Build a spherical coordinates transformer from Cartesian coordinates.
Parameters:
v - Cartesian coordinates
• #### SphericalCoordinates

public SphericalCoordinates(double r,
double theta,
double phi)
Build a spherical coordinates transformer from spherical coordinates.
Parameters:
theta - azimuthal angle in x-y plane
phi - polar (co-latitude) angle
• ### Method Detail

• #### getCartesian

public Vector3D getCartesian()
Get the Cartesian coordinates.
Returns:
Cartesian coordinates
• #### getR

public double getR()
Returns:
getTheta(), getPhi()
• #### getTheta

public double getTheta()
Get the azimuthal angle in x-y plane.
Returns:
azimuthal angle in x-y plane θ
getR(), getPhi()
• #### getPhi

public double getPhi()
Get the polar (co-latitude) angle.
Returns:
polar (co-latitude) angle Φ
getR(), getTheta()

Convert a gradient with respect to spherical coordinates into a gradient with respect to Cartesian coordinates.
Parameters:
Returns:
gradient with respect to Cartesian coordinates {df/dx, df/dy, df/dz}
• #### toCartesianHessian

public double[][] toCartesianHessian(double[][] sHessian,