00001 #pragma ident "$Id: ECEF.cpp 2944 2011-10-27 08:04:41Z yanweignss $" 00002 00003 00004 00005 //============================================================================ 00006 // 00007 // This file is part of GPSTk, the GPS Toolkit. 00008 // 00009 // The GPSTk is free software; you can redistribute it and/or modify 00010 // it under the terms of the GNU Lesser General Public License as published 00011 // by the Free Software Foundation; either version 2.1 of the License, or 00012 // any later version. 00013 // 00014 // The GPSTk is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with GPSTk; if not, write to the Free Software Foundation, 00021 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 // 00023 // Copyright 2004, The University of Texas at Austin 00024 // 00025 //============================================================================ 00026 00027 //============================================================================ 00028 // 00029 //This software developed by Applied Research Laboratories at the University of 00030 //Texas at Austin, under contract to an agency or agencies within the U.S. 00031 //Department of Defense. The U.S. Government retains all rights to use, 00032 //duplicate, distribute, disclose, or release this software. 00033 // 00034 //Pursuant to DoD Directive 523024 00035 // 00036 // DISTRIBUTION STATEMENT A: This software has been approved for public 00037 // release, distribution is unlimited. 00038 // 00039 //============================================================================= 00040 00041 00042 00043 00044 00045 00051 #include "geometry.hpp" 00052 #include "ECEF.hpp" 00053 #include "Geodetic.hpp" 00054 #include "MiscMath.hpp" 00055 00056 namespace gpstk 00057 { 00058 using namespace std; 00059 00060 ECEF :: ECEF() 00061 : Triple() 00062 { 00063 } 00064 00065 ECEF :: ECEF(const ECEF& right) 00066 : Triple(right) 00067 { 00068 } 00069 00070 ECEF& ECEF :: operator=(const ECEF& right) 00071 { 00072 Triple::operator=(right); 00073 return *this; 00074 } 00075 00076 // Convert Earth-centered, Earth-fixed XYZ coordinates (m) 00077 // to Geodetic coordinates (lat,lon(E),ht) (deg,degE,m). 00078 Geodetic ECEF::asGeodetic(GeoidModel* geoid) 00079 { 00080 double X = this->operator[](0); //ecef[0]; // m 00081 double Y = this->operator[](1); //ecef[1]; // m 00082 double Z = this->operator[](2); //ecef[2]; // m 00083 double p = RSS(X,Y); 00084 double latd = ::atan2(Z,p*(1.0-geoid->eccSquared())); 00085 double ht = 0.0, slatd, N, htold, latdold; 00086 for(int i=0; i<5; i++) { 00087 slatd = ::sin(latd); 00088 N = geoid->a() / SQRT(1.0-geoid->eccSquared()*slatd*slatd); 00089 htold = ht; 00090 ht = p/::cos(latd) - N; 00091 latdold = latd; 00092 latd = ::atan2(Z,p*(1.0-geoid->eccSquared()*(N/(N+ht)))); 00093 if(ABS(latd-latdold) < 1.0e-9 && 00094 ABS(ht-htold) < (1.0e-9*geoid->a())) break; 00095 } 00096 double lon = ::atan2(Y,X); 00097 if(lon < 0.0) lon += 6.2831853071796; 00098 00099 Geodetic g(latd*RAD_TO_DEG,lon*RAD_TO_DEG,ht,geoid); // deg,deg E,m 00100 return g; 00101 00102 } // end asGeodetic(geoid) 00103 00104 } // namespace gpstk
1.3.9.1