sph2cart

Converts spherical coordinates to Cartesian.

Category: Mathematics > Elementary Math

Syntax

[x, y, z] = sph2cart(azimuth, elevation, r)

Converts spherical coordinates to Cartesian x, y and z.

Description

The formulas are x = r.*cos(elevation).*cos(azimuth), y = r.*cos(elevation).*sin(azimuth) and z = r.*sin(elevation). The elevation is measured from the equator, not from the pole as in the physics convention of a polar angle, so the north pole is at pi/2.

The inverse is cart2sph.

Input arguments

azimuth
Angle in radians in the xy plane, counterclockwise from the positive x axis.
elevation
Angle in radians up from the xy plane: 0 on the plane and pi/2 at the positive z axis.
r
Distance from the origin.

Output arguments

x, y, z
Cartesian coordinates, with the size given by implicit expansion of the inputs.

Example

Points on a sphere

[x, y, z] = sph2cart([0 pi/2], [0 0], 2);
round([x; y; z], 10)
[x, y, z] = sph2cart(0, pi/2, 1);
round([x y z], 10)
Output
ans = 3×2

     2     0
     0     2
     0     0
ans = 1×3

     0     0     1

See also

cart2sph pol2cart cart2pol sin cos