sph2cart
Converts spherical coordinates to Cartesian.
Syntax
[x,y,z] = sph2cart(theta, phi, r)
[x,y,z] = sph2cart(S)
C = sph2cart(...)
Inputs
- theta, phi, r
- Spherical coordinates. See Comments.
- S
- An array or matrix containing spherical coordinates.
Outputs
- x,y,z
- Cartesian coordinates.
- C
- An array or matrix containing Cartesian coordinates.
Examples
Single return sph2cart
example:
C = sph2cart([pi/4,pi/3,1;pi/2,pi/6,3])
C = [Matrix] 2 x 3
6.12372e-01 6.12372e-01 5.00000e-01
9.18485e-17 1.50000e+00 2.59808e+00
Multiple return sph2cart
example:
[x,y,z] = sph2cart([pi,pi/3,pi/4],pi/6,[2,3,4])
x = [Matrix] 1 x 3
-1.00000 0.75000 1.41421
y = [Matrix] 1 x 3
1.22465e-16 1.29904e+00 1.41421e+00
z = [Matrix] 1 x 3
1.73205 2.59808 3.46410
Comments
When a matrix contains multiple points the coordinates are stored by row.
theta is the angle in the xy-plane measured from the positive x-axis.
phi is the angle measured from the positive z-axis.