vec2ang

Cartesian vector to polar angles conversion.

Syntax
[phi,theta] = vec2ang(v)
angles = vec2ang(v)
___ = vec2ang(x,y,z)
Description

This function converts 3D cartesian coordinates to polar angles.

v is a 3-by-N array where each column represents one cartesian vector. It can also be a Mx3 array (list of row vectors). If it is a 3x3 array, the vectors are assumed to be along columns.

Alternatively, v accepts short letter abbreviations to indicate one from a set of standard directions: 'x', 'y', 'z', 'xy', 'xz', 'yz', 'xyz', and combinations of these with a leading '-', such as '-z'.

Instead of providing an array of vectors in 'v', one can use x, y, and z to specify the three components of the vector or vectors separately.

The vectors in v (or x, y, z) don't have to be normalized.

The output phi denotes the counterclockwise angle between the x axis and the projection of a vector onto the xy plane (azimuth), and theta is the angle from the z axis down to the vector (polar angle, colatitude, inclination, elevation complement).

If only one output argument is requested, an array angles is returned that contains the phi values in the first row and the theta values in the second row.

Examples

Convert a list of 5 unnormalized column vectors to angles:

v = rand(3,5);
[ph,th] = vec2ang(v);
th*180/pi
ph*180/pi
ans =
   71.233       86.793       33.626       65.537       28.961
ans =
   59.228       26.317       43.952        25.13       9.5241
See also

ang2vec, erot, eulang