Home > atmlab > geodetic > cart2geocentric.m

cart2geocentric

PURPOSE ^

CART2GEOCENTRIC converts a cartesian position to spherical coordinate

SYNOPSIS ^

function [r,lat,lon]=cart2geocentric(x,y,z,lat0,lon0,za0,aa0)

DESCRIPTION ^

 CART2GEOCENTRIC   converts a cartesian position to spherical coordinate 

   The geocentric Cartesian coordinate system is fixed with respect to the
   Earth, with its origin at the center of the ellipsoid and its X-, Y-,
   and Z-axes intersecting the surface at the following points:
 
                 lat   lon
       X-axis:    0     0      (Equator at the Prime Meridian)
       Y-axis:    0    90      (Equator at 90-degrees East)
       Z-axis:   90     0      (North Pole)
 
    A common synonym is Earth-Centered, Earth-Fixed coordinates, or ECEF.

    If the optional arguments are given, it is ensured that latitude and
    longitude are kept constant for zenith or nadir cases, and the longitude
    for N-S cases. The optional input shall be interpreted as the [x,y,z]
    is obtained by moving from [lat0,lon0] in the direction of [za0,aa0].
 
 FORMAT  [r,lat,lon]=cart2geocentric(x,y,z[,lat0,lon0,za0,aa0]) 

 OUT     r      Radius 
         lat    Latitude
         lon    Longitude
 IN      x      Coordinate in x dimension
         y      Coordinate in y dimension
         z      Coordinate in z dimension
         lat0   Original latitude
         lon0   Original longitude
         za0    Orignal zenith angle
         aa0    Orignal azimuth angle

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

cart2geocentric.m

SOURCE CODE ^

0001 % CART2GEOCENTRIC   converts a cartesian position to spherical coordinate
0002 %
0003 %   The geocentric Cartesian coordinate system is fixed with respect to the
0004 %   Earth, with its origin at the center of the ellipsoid and its X-, Y-,
0005 %   and Z-axes intersecting the surface at the following points:
0006 %
0007 %                 lat   lon
0008 %       X-axis:    0     0      (Equator at the Prime Meridian)
0009 %       Y-axis:    0    90      (Equator at 90-degrees East)
0010 %       Z-axis:   90     0      (North Pole)
0011 %
0012 %    A common synonym is Earth-Centered, Earth-Fixed coordinates, or ECEF.
0013 %
0014 %    If the optional arguments are given, it is ensured that latitude and
0015 %    longitude are kept constant for zenith or nadir cases, and the longitude
0016 %    for N-S cases. The optional input shall be interpreted as the [x,y,z]
0017 %    is obtained by moving from [lat0,lon0] in the direction of [za0,aa0].
0018 %
0019 % FORMAT  [r,lat,lon]=cart2geocentric(x,y,z[,lat0,lon0,za0,aa0])
0020 %
0021 % OUT     r      Radius
0022 %         lat    Latitude
0023 %         lon    Longitude
0024 % IN      x      Coordinate in x dimension
0025 %         y      Coordinate in y dimension
0026 %         z      Coordinate in z dimension
0027 %         lat0   Original latitude
0028 %         lon0   Original longitude
0029 %         za0    Orignal zenith angle
0030 %         aa0    Orignal azimuth angle
0031 
0032 % History: created by Bengt Rydberg 2011-10-31
0033 
0034 function [r,lat,lon]=cart2geocentric(x,y,z,lat0,lon0,za0,aa0)
0035 
0036 rad2deg = constants( 'RAD2DEG' );
0037 
0038 
0039 r   = sqrt( x.*x + y.*y + z.*z );
0040 if all( r > 0 )
0041   lat = rad2deg * asin( z ./ r );
0042 else
0043   error( 'This set of functions are not handling the case of r = 0.' );
0044 end
0045 lon = rad2deg * atan2( y, x ); 
0046 
0047 
0048 if nargin > 3
0049   
0050   n = length(r);
0051   
0052   for i = 1 : n
0053 
0054     %Zenith or nadir?
0055     if za0(i) < 1e-6  |  za0(i) > 180-1e-6 
0056       lat(i) = lat0(i);
0057       lon(i) = lon0(i);
0058     end
0059     
0060     % N-S case (not starting at a pole)?
0061     if abs(lat0(i)) < 90-1e-8  & ...
0062       ( abs(aa0(i)) < 1e-6  |  abs(aa0(i)-180) < 1e-6 )
0063       % Check that not lon changed with 180 deg
0064       if abs(lon(i)-lon0(i)) < 1 
0065         lon(i) = lon0(i);
0066       else
0067         if lon0(i) > 0
0068           lon(i) = lon0(i) - 180;
0069         else
0070           lon(i) = lon0(i) + 180;
0071         end          
0072       end
0073     end      
0074   end
0075   
0076 end
0077 
0078

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005