cart2sph

Converts Cartesian coordinates to spherical.

Syntax

[theta,phi,r] = cart2sph (x, y, z)

[theta,phi,r] = cart2sph (C)

S = cart2sph (...)

Inputs

x, y, z
Cartesian coordinates.
Type: double
Dimension: scalar | vector
C
An array or matrix containing Cartesian coordinates.
Type: double
Dimension: vector | matrix

Outputs

theta
The angle measured from the positive x-axis.
phi
The angle measured from the z-axis.
r
The resulting distance between the point and the origin.
S
A matrix containing theta, phi, and r.

Examples

Single return cart2sph example:

S = cart2sph([3,4,5;1,2,3])
S = [Matrix] 2 x 3
0.92730  0.78540  7.07107
1.10715  0.64052  3.74166

Multiple return cart2sph example:

[theta,phi,r] = cart2sph(3,4,5)
theta = 0.927295218
phi = 0.785398163
r = 7.07106781

Comments

When a matrix contains multiple points the coordinates are stored by row.