ang2vec

Polar angles to cartesian vector conversion.

Syntax
V = ang2vec(phi,theta)
[x,y,z] = ang2vec(phi,theta)
Description

This function converts polar angles to cartesian coordinates. Given the two polar angles phi and theta (both in radians), it returns a column vector representing the cartesian unit vector V pointing in the specified direction.

phi denotes the counterclockwise angle between the x axis and the projection of a vector onto the xy plane (azimuth), theta is the angle between a vector and the z axis (colatitude, elevation complement).

phi and theta may be arrays, but must have the same number of elements. In that case ang2vec returns an array with 3 rows and as many columns as there are elements in phi, where V(:,k) represents the unit vector for the orientation given by phi(k) and theta(k).

If three outputs are requested, x contains all the x coordinates, y all the y coordinates and z all the z coordinates of the unit vectors.

In MATLAB's functions sph2cart and cart2sph, a different convention is used where theta denotes the azimuth and phi the elevation.

Examples

If you want to create a set of n equidistant orientations on the equator, i.e. with theta=pi/2, use

n = 6;
phi = linspace(0,2*pi,n);
theta = pi/2*ones(1,n);
vecs = ang2vec(phi,theta)

In the result, the cartesian unit vectors are along the columns.

vecs =
    1.0000    0.3090   -0.8090   -0.8090    0.3090    1.0000
         0    0.9511    0.5878   -0.5878   -0.9511   -0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000
See also

erot, eulang, vec2ang