Home > pointing > cosined.m

cosined

PURPOSE ^

--------------------------------------------------------------------

SYNOPSIS ^

function Res=cosined(Vec);

DESCRIPTION ^

--------------------------------------------------------------------
 cosined function     cosine direction transformation
                    convert lon & lat to cosine direction
                    and visa versa. UNITS are in radians!
 input  : - column matrix, with 2 or 3 colums.
            if 2 colums are given then, the first column
            is longitude and the second is latitude.
            and the cosine direction are returned.
            if three columns are given, then they suppose to
            be the cosine direction, and the longitude
            and latitude are returned.
 output : - cosine direction or longitude and latitude.
    By  Eran O. Ofek           July 1999
--------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Res=cosined(Vec);
0002 %--------------------------------------------------------------------
0003 % cosined function     cosine direction transformation
0004 %                    convert lon & lat to cosine direction
0005 %                    and visa versa. UNITS are in radians!
0006 % input  : - column matrix, with 2 or 3 colums.
0007 %            if 2 colums are given then, the first column
0008 %            is longitude and the second is latitude.
0009 %            and the cosine direction are returned.
0010 %            if three columns are given, then they suppose to
0011 %            be the cosine direction, and the longitude
0012 %            and latitude are returned.
0013 % output : - cosine direction or longitude and latitude.
0014 %    By  Eran O. Ofek           July 1999
0015 %--------------------------------------------------------------------
0016 if (length(Vec(1,:))==2),
0017    Alpha = Vec(:,1);
0018    Delta = Vec(:,2);
0019    Res          = zeros(length(Vec(:,1)),3);
0020    Res(:,1)     = cos(Alpha).*cos(Delta);
0021    Res(:,2)     = sin(Alpha).*cos(Delta);
0022    Res(:,3)     = sin(Delta);
0023 elseif (length(Vec(1,:))==3),
0024    L1           = Vec(:,1);
0025    L2           = Vec(:,2);
0026    L3           = Vec(:,3);
0027    Res          = zeros(length(Vec(:,1)),2);
0028    Res(:,1)     = atan2(L2,L1);                 % Alpha
0029    SLL          = sqrt(L1.^2+L2.^2);
0030    I0  = find(SLL==0);
0031    In0 = find(SLL~=0);
0032    Res(In0,2)     = atan(L3(In0)./SLL(In0));  % Delta
0033    Res(I0,2)      = sign(L3(I0)).*pi./2;  % Delta
0034 else
0035    error('only 2/3 columns are allowed');
0036 end

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005