LocalCartesian.cpp

Go to the documentation of this file.
00001 /**
00002  * \file LocalCartesian.cpp
00003  * \brief Implementation for GeographicLib::LocalCartesian class
00004  *
00005  * Copyright (c) Charles Karney (2008, 2009, 2010) <charles@karney.com>
00006  * and licensed under the LGPL.  For more information, see
00007  * http://geographiclib.sourceforge.net/
00008  **********************************************************************/
00009 
00010 #include "GeographicLib/LocalCartesian.hpp"
00011 
00012 #define GEOGRAPHICLIB_LOCALCARTESIAN_CPP "$Id: LocalCartesian.cpp 6785 2010-01-05 22:15:42Z karney $"
00013 
00014 RCSID_DECL(GEOGRAPHICLIB_LOCALCARTESIAN_CPP)
00015 RCSID_DECL(GEOGRAPHICLIB_LOCALCARTESIAN_HPP)
00016 
00017 namespace GeographicLib {
00018 
00019   using namespace std;
00020 
00021   void LocalCartesian::Reset(real lat0, real lon0, real h0) throw() {
00022     _lat0 = lat0;
00023     _lon0 = lon0 >= 180 ? lon0 - 360 : lon0 < -180 ? lon0 + 360 : lon0;
00024     _h0 = h0;
00025     _earth.Forward(_lat0, _lon0, _h0, _x0, _y0, _z0);
00026     real
00027       phi = lat0 * Constants::degree(),
00028       sphi = sin(phi),
00029       cphi = abs(_lat0) == 90 ? 0 : cos(phi),
00030       lam = lon0 * Constants::degree(),
00031       slam = _lon0 == -180 ? 0 : sin(lam),
00032       clam = abs(_lon0) == 90 ? 0 : cos(lam);
00033     // Local x axis in geocentric coords
00034     _rxx = -slam; _rxy = clam; _rxz = 0;
00035     // Local y axis in geocentric coords
00036     _ryx = -clam * sphi; _ryy = -slam * sphi; _ryz = cphi;
00037     // Local z axis in geocentric coords
00038     _rzx = clam * cphi; _rzy = slam * cphi; _rzz = sphi;
00039   }
00040 
00041   void LocalCartesian::Forward(real lat, real lon, real h,
00042                                real& x, real& y, real& z) const throw() {
00043     real xc, yc, zc;
00044     _earth.Forward(lat, lon, h, xc, yc, zc);
00045     xc -= _x0; yc -= _y0; zc -= _z0;
00046     x = _rxx * xc + _rxy * yc + _rxz * zc;
00047     y = _ryx * xc + _ryy * yc + _ryz * zc;
00048     z = _rzx * xc + _rzy * yc + _rzz * zc;
00049   }
00050 
00051   void LocalCartesian::Reverse(real x, real y, real z,
00052                                real& lat, real& lon, real& h) const throw() {
00053     real
00054       xc = _x0 + _rxx * x + _ryx * y + _rzx * z,
00055       yc = _y0 + _rxy * x + _ryy * y + _rzy * z,
00056       zc = _z0 + _rxz * x + _ryz * y + _rzz * z;
00057     _earth.Reverse(xc, yc, zc, lat, lon, h);
00058   }
00059 
00060 } // namespace GeographicLib

Generated on 21 May 2010 for GeographicLib by  doxygen 1.6.1