Home > atmlab > geodetic > cart2geodetic.m

cart2geodetic

PURPOSE ^

CART2GEODETIC converts from cartesian to a geodetic coordinates

SYNOPSIS ^

function [h, lat, lon] = cart2geodetic(x,y,z,ellipsoid)

DESCRIPTION ^

 CART2GEODETIC    converts from cartesian to a geodetic coordinates

   The geodetic coordinates refer to the reference ellipsoid 
   specified by input ellipsoid. 
   See Contents for a defintion of the geocentric coordinate system.

 FORMAT [h, lat, lon] = cart2geodetic(x,y,z[,ellipsoid]) 

 OUT    h    Geodetic height (height above the reference ellipsoid)
        lat  Geodetic latitude
        lon  Geodetic longitude

 IN     x    Coordinate in x dimension
        y    Coordinate in y dimension
        z    Coordinate in z dimension
 OPT    ellipsoid   a row vector with the form [semimajor axis, eccentricity]
                    specifying the ellipsoid,
                    Default is WGS84.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

cart2geodetic.m

SOURCE CODE ^

0001 % CART2GEODETIC    converts from cartesian to a geodetic coordinates
0002 %
0003 %   The geodetic coordinates refer to the reference ellipsoid
0004 %   specified by input ellipsoid.
0005 %   See Contents for a defintion of the geocentric coordinate system.
0006 %
0007 % FORMAT [h, lat, lon] = cart2geodetic(x,y,z[,ellipsoid])
0008 %
0009 % OUT    h    Geodetic height (height above the reference ellipsoid)
0010 %        lat  Geodetic latitude
0011 %        lon  Geodetic longitude
0012 %
0013 % IN     x    Coordinate in x dimension
0014 %        y    Coordinate in y dimension
0015 %        z    Coordinate in z dimension
0016 % OPT    ellipsoid   a row vector with the form [semimajor axis, eccentricity]
0017 %                    specifying the ellipsoid,
0018 %                    Default is WGS84.
0019 
0020 % History: created by Bengt Rydberg 2011-10-31
0021 
0022 function [h, lat, lon] = cart2geodetic(x,y,z,ellipsoid)
0023 
0024 if nargin<4
0025   %WGS84 reference ellipsoid
0026   ellipsoid = ellipsoidmodels( 'WGS84' );
0027 end 
0028 
0029 rad2deg = constants( 'RAD2DEG' );
0030 %longitude
0031 lon=atan2(y,x)*rad2deg;
0032 
0033 % Latitude
0034 B0=atan2(z,sqrt(x.^2+y.^2));
0035 B=ones(size(B0));
0036 e2=ellipsoid(2)^2;
0037 while(any(abs(B-B0)>1e-10))
0038     N=ellipsoid(1)./sqrt(1-e2*sin(B0).^2);
0039     h=sqrt(x.^2+y.^2)./cos(B0)-N;
0040     B=B0;
0041     B0=atan((z./sqrt(x.^2+y.^2)).*(1-e2*N./(N+h)).^(-1));
0042 end
0043 lat=B*rad2deg;
0044 
0045 
0046

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