Cartesian vector to polar angles conversion.
[phi,theta] = vec2ang(Vecs) angles = vec2ang(Vecs)
This function converts 3D cartesian coordinates to polar angles. Given one or
more cartesian vectors in Vecs, vec2ang returns
the corresponding polar angles phi and theta,
both in radians.
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
(polar angle, colatitude, 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.
Vecs can be a 3xN array (list of column vectors) or an Mx3 array
(list of row vectors). If it is a 3x3 array, the vectors are assumed to be
along columns.
The vectors in Vecs don't have to be normalized.
A set of vectors with linearly increasing z coordinate gives polar
angles where theta is not linearly decreasing.
v = ones(3,6); v(3,:) = linspace(0,9,6); [ph,th] = vec2ang(v); th*180/pi
ans = 90.0000 38.1558 21.4467 14.6757 11.1125 8.9301