Top Description Inners Fields Constructors Methods
org.apache.commons.math3.geometry.euclidean.threed

public Class SphericalCoordinates

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, org.apache.commons.math3.util.FastMath

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:

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
SphericalCoordinates.DataTransferObject

Internal class used only for serialization.

Field Summary

Modifier and TypeField and Description
private double[][]
jacobian

Jacobian of (r, θ Φ).

private final double
phi

Polar angle (co-latitude) Φ.

private double[][]
phiHessian

Hessian of polar (co-latitude) angle Φ.

private final double
r

Radius.

private double[][]
rHessian

Hessian of radius.

private static final long
serialVersionUID

Serializable UID.

private final double
theta

Azimuthal angle in the x-y plane θ.

private double[][]
thetaHessian

Hessian of azimuthal angle in the x-y plane θ.

private final Vector3D
v

Cartesian coordinates.

Constructor Summary

AccessConstructor and Description
public
SphericalCoordinates(final Vector3D
Cartesian coordinates
v
)

Build a spherical coordinates transformer from Cartesian coordinates.

public
SphericalCoordinates(final double
radius
r
,
final double
azimuthal angle in x-y plane
theta
,
final double
polar (co-latitude) angle
phi
)

Build a spherical coordinates transformer from spherical coordinates.

Method Summary

Modifier and TypeMethod and Description
private void
computeHessians()

Lazy evaluation of Hessians.

private void
computeJacobian()

Lazy evaluation of (r, θ, φ) Jacobian.

public Vector3D

Returns:

Cartesian coordinates
getCartesian
()

Get the Cartesian coordinates.

public double

Returns:

polar (co-latitude) angle Φ
getPhi
()

Get the polar (co-latitude) angle.

public double

Returns:

radius r
getR
()

Get the radius.

public double

Returns:

azimuthal angle in x-y plane θ
getTheta
()

Get the azimuthal angle in x-y plane.

public double[]

Returns:

gradient with respect to Cartesian coordinates {df/dx, df/dy, df/dz}
toCartesianGradient
(final double[]
gradient with respect to spherical coordinates {df/dr, df/dθ, df/dΦ}
sGradient
)

Convert a gradient with respect to spherical coordinates into a gradient with respect to Cartesian coordinates.

public double[][]

Returns:

Hessian with respect to Cartesian coordinates {{d2f/dx2, d2f/dxdy, d2f/dxdz}, {d2f/dxdy, d2f/dy2, d2f/dydz}, {d2f/dxdz, d2f/dydz, d2f/dz2}}
toCartesianHessian
(final double[][]
Hessian with respect to spherical coordinates {{d2f/dr2, d2f/drdθ, d2f/drdΦ}, {d2f/drdθ, d2f/dθ2, d2f/dθdΦ}, {d2f/drdΦ, d2f/dθdΦ, d2f/dΦ2}
sHessian
,
final double[]
gradient with respect to spherical coordinates {df/dr, df/dθ, df/dΦ}
sGradient
)

Convert a Hessian with respect to spherical coordinates into a Hessian with respect to Cartesian coordinates.

private Object

Returns:

data transfer object that will be serialized
writeReplace
()

Replace the instance with a data transfer object for serialization.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

jacobianback to summary
private double[][] jacobian

Jacobian of (r, θ &Phi).

phiback to summary
private final double phi

Polar angle (co-latitude) Φ.

phiHessianback to summary
private double[][] phiHessian

Hessian of polar (co-latitude) angle Φ.

rback to summary
private final double r

Radius.

rHessianback to summary
private double[][] rHessian

Hessian of radius.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable UID.

thetaback to summary
private final double theta

Azimuthal angle in the x-y plane θ.

thetaHessianback to summary
private double[][] thetaHessian

Hessian of azimuthal angle in the x-y plane θ.

vback to summary
private final Vector3D v

Cartesian coordinates.

Constructor Detail

SphericalCoordinatesback to summary
public SphericalCoordinates(final Vector3D v)

Build a spherical coordinates transformer from Cartesian coordinates.

Parameters
v:Vector3D

Cartesian coordinates

SphericalCoordinatesback to summary
public SphericalCoordinates(final double r, final double theta, final double phi)

Build a spherical coordinates transformer from spherical coordinates.

Parameters
r:double

radius

theta:double

azimuthal angle in x-y plane

phi:double

polar (co-latitude) angle

Method Detail

computeHessiansback to summary
private void computeHessians()

Lazy evaluation of Hessians.

computeJacobianback to summary
private void computeJacobian()

Lazy evaluation of (r, θ, φ) Jacobian.

getCartesianback to summary
public Vector3D getCartesian()

Get the Cartesian coordinates.

Returns:Vector3D

Cartesian coordinates

getPhiback to summary
public double getPhi()

Get the polar (co-latitude) angle.

Returns:double

polar (co-latitude) angle Φ

See Also
getR(), getTheta()
getRback to summary
public double getR()

Get the radius.

Returns:double

radius r

See Also
getTheta(), getPhi()
getThetaback to summary
public double getTheta()

Get the azimuthal angle in x-y plane.

Returns:double

azimuthal angle in x-y plane θ

See Also
getR(), getPhi()
toCartesianGradientback to summary
public double[] toCartesianGradient(final double[] sGradient)

Convert a gradient with respect to spherical coordinates into a gradient with respect to Cartesian coordinates.

Parameters
sGradient:double[]

gradient with respect to spherical coordinates {df/dr, df/dθ, df/dΦ}

Returns:double[]

gradient with respect to Cartesian coordinates {df/dx, df/dy, df/dz}

toCartesianHessianback to summary
public double[][] toCartesianHessian(final double[][] sHessian, final double[] sGradient)

Convert a Hessian with respect to spherical coordinates into a Hessian with respect to Cartesian coordinates.

As Hessian are always symmetric, we use only the lower left part of the provided spherical Hessian, so the upper part may not be initialized. However, we still do fill up the complete array we create, with guaranteed symmetry.

Parameters
sHessian:double[][]

Hessian with respect to spherical coordinates {{d2f/dr2, d2f/drdθ, d2f/drdΦ}, {d2f/drdθ, d2f/dθ2, d2f/dθdΦ}, {d2f/drdΦ, d2f/dθdΦ, d2f/dΦ2}

sGradient:double[]

gradient with respect to spherical coordinates {df/dr, df/dθ, df/dΦ}

Returns:double[][]

Hessian with respect to Cartesian coordinates {{d2f/dx2, d2f/dxdy, d2f/dxdz}, {d2f/dxdy, d2f/dy2, d2f/dydz}, {d2f/dxdz, d2f/dydz, d2f/dz2}}

writeReplaceback to summary
private Object writeReplace()

Replace the instance with a data transfer object for serialization.

Returns:Object

data transfer object that will be serialized

org.apache.commons.math3.geometry.euclidean.threed back to summary

private Class SphericalCoordinates.DataTransferObject

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.geometry.euclidean.threed.SphericalCoordinates.DataTransferObject
All Implemented Interfaces
java.io.Serializable

Internal class used only for serialization.

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Serializable UID.

private final double
x

Abscissa.

private final double
y

Ordinate.

private final double
z

Height.

Constructor Summary

AccessConstructor and Description
pack-priv
DataTransferObject(final double
abscissa
x
,
final double
ordinate
y
,
final double
height
z
)

Simple constructor.

Method Summary

Modifier and TypeMethod and Description
private Object

Returns:

replacement SphericalCoordinates
readResolve
()

Replace the deserialized data transfer object with a SphericalCoordinates.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable UID.

xback to summary
private final double x

Abscissa.

yback to summary
private final double y

Ordinate.

zback to summary
private final double z

Height.

Constructor Detail

DataTransferObjectback to summary
pack-priv DataTransferObject(final double x, final double y, final double z)

Simple constructor.

Parameters
x:double

abscissa

y:double

ordinate

z:double

height

Method Detail

readResolveback to summary
private Object readResolve()

Replace the deserialized data transfer object with a SphericalCoordinates.

Returns:Object

replacement SphericalCoordinates