www.pudn.com > calibr8.zip > dir2angle.m


function angles = dir2angle(directions)
%angles = DIR2ANGLE(directions)
%
%Convert directions to azimuth/elevation pairs
%
%Input:
%  DIRECTIONS - directions vectors (array N x 3)
%
%Output:
%  ANGLES     - azimuths and elevations of the directions (array N x 2,
%               in the range <0, 360) x  <-90, 90> degrees)
%
%See also:
%  ANGLE2DIR, DIR2ROT
%
%Radim Halir, Charles University Prague, halir@ms.mff.cuni.cz
%Created: 12.6.1997
%Last modified 2.9.1997

x = directions(:, 1);
y = directions(:, 2);
z = directions(:, 3);

azimuths = atan2(y, x);
elevations = atan2(z, sqrt(x .^ 2 + y .^ 2));
ind = (azimuths < 0);
azimuths(ind) = azimuths(ind) + 2 * pi;
angles = [azimuths, elevations] / pi * 180;