Convert Cartesian XYZ coordinates to spherical coordinates.
CART2SPH(x, y, z, "degrees")
(az, el, r) = CART2SPH(x, y, z, "degrees")
x |
- |
A real or series, the X coordinate. |
y |
- |
A real or series, the Y coordinate. |
z |
- |
A real or series, the Z coordinate. |
"degrees" |
- |
Optional. A string, if "degrees", all output angles are in degrees. If "radians" or not specified, the output angles are in radians. |
CART2SPH(xyzcoords, "degrees")
(az, el, r) = CART2SPH(xyzcoords, "degrees")
xyzcoords |
- |
A 3 column series, where X is the first column, Y the second column and Z the third column. |
"degrees" |
- |
Optional. A string, if "degrees", all output angles are in degrees. If "radians" or not specified, the output angles are in radians. |
A three column series where the first column is azimuth, the second column is elevation and the third column is the radius.
(az, el, r) = CART2SPH(x, y, z) returns the spherical coordinates as separate series.
W1: cart2sph(1.0, 1.0, sqrt(2))
W1 == {{0.785398, 0.785398, 2}}
W1 transforms the XYZ coordinate with an X of 1 unit, a Y of 1 unit and Z of sqrt(2) to a spherical coordinate. The result is a 1x3 array where the azimuth value is π/4 radians, the elevation value is π/4 radians and the radius is 2 units.
W1: cart2sph(1.0, 1.0, sqrt(2), "degrees")
W1 == {{45, 45, 2}}
Same as above except azimuth and elevation are in degrees.
W2: {{1.0, 1.0, sqrt(2)}}
W3: cart2sph(w2, "degrees")
W3 == {{45, 45, 2}}
Same as above except the input Cartesian coordinates are contained in a single 3 column series.
W4: {{1.0, 1.0, sqrt(2)}}
(az, el, r) = cart2sph(w4, "degrees");
az == {45}
el == {45}
r == {2}
Same as above except the output spherical coordinates are contained in three separate variables.
W1: {{1.0, 1.0, sqrt(2)}}
W2: cart2sph(w1)
W3: sph2cart(w2)
W1 == {{1.0, 1.0, 1.414214}}
W2 == {{0.785398, 0.785398, 2.0}}
W3 == {{1.0, 1.0, 1.414214}}
Demonstrates that CART2SPH and SPH2CART are inverse functions.
CART2SPH transforms Cartesian XYZ coordinates to azimuth, elevation and radius spherical coordinates.
Azimuth (az) is measured counterclockwise from the positive X axis in the X-Y plane. Azimuth is in radians unless "degrees" is specified. Azimuth varies from 0 to 2π radians or 0 to 360 degrees.
Elevation (el) is measured from the X-Y plane. Elevation is in radians unless "degrees" is specified. Elevation varies from -π/2 to π/2 radians or -90 to 90 degrees.
Radius (r) is the length of the 3D vector.
If "degrees" is specified, the output azimuth and elevation angles are in degrees. If "radians" or not specified, azimuth and elevation are in radians.