LocalCartesian.hpp
Go to the documentation of this file.
00001 /**
00002  * \file LocalCartesian.hpp
00003  * \brief Header for GeographicLib::LocalCartesian class
00004  *
00005  * Copyright (c) Charles Karney (2008) <charles@karney.com>
00006  * and licensed under the LGPL.
00007  **********************************************************************/
00008 
00009 #if !defined(LOCALCARTESIAN_HPP)
00010 #define LOCALCARTESIAN_HPP "$Id: LocalCartesian.hpp 6538 2009-02-14 13:47:53Z ckarney $"
00011 
00012 #include "GeographicLib/Geocentric.hpp"
00013 
00014 namespace GeographicLib {
00015 
00016   /**
00017    * \brief Local Cartesian coordinates
00018    *
00019    * Convert between geodetic coordinates latitude = \e lat, longitude = \e
00020    * lon, height = \e h (measured vertically from the surface of the ellipsoid)
00021    * to local cartesian coordinates (\e x, \e y, \e z).  The origin of local
00022    * cartesian coordinate system is at \e lat = \e lat0, \e lon = \e lon0, \e h
00023    * = \e h0. The \e z axis is normal to the ellipsoid; the \e y axis points due
00024    * north.  The plane \e z = - \e h0 is tangent to the ellipsoid.
00025    *
00026    * The conversions all take place via geocentric coordinates using a
00027    * GeographicLib::GeoCentric object (by default
00028    * GeographicLib::Geocentric::WGS84).
00029    **********************************************************************/
00030 
00031   class LocalCartesian {
00032   private:
00033     const Geocentric& _earth;
00034     double _lat0, _lon0, _h0;
00035     double _x0, _y0, _z0,
00036       _rxx, _rxy, _rxz,
00037       _ryx, _ryy, _ryz,
00038       _rzx, _rzy, _rzz;
00039   public:
00040 
00041     /**
00042      * Constructor setting the origin to latitude = \e lat0, longitude = \e
00043      * lon0 (degrees), height = \e h0 (meters).  The optional \e earth argument
00044      * (default Geocentric::WGS84) specifies the Geocentric object to use for
00045      * the transformation.
00046      **********************************************************************/
00047     LocalCartesian(double lat0, double lon0, double h0 = 0,
00048                    const Geocentric& earth = Geocentric::WGS84) throw()
00049       : _earth(earth)
00050     { Reset(lat0, lon0, h0); }
00051 
00052     /**
00053      * Default constructor sets the origin to \e lat0 = 0, \e lon0 = 0, \e h0 =
00054      * 0.  The optional \e earth argument (default Geocentric::WGS84) specifies
00055      * the Geocentric object to use for the transformation.
00056      **********************************************************************/
00057     LocalCartesian(const Geocentric& earth = Geocentric::WGS84) throw()
00058       : _earth(earth)
00059     { Reset(0.0, 0.0, 0.0); }
00060 
00061     /**
00062      * Change the origin to latitude = \e lat0, longitude = \e lon0 (degrees),
00063      * height = \e h0 (meters).
00064      **********************************************************************/
00065     void Reset(double lat0, double lon0, double h0 = 0) throw();
00066 
00067     /**
00068      * Convert from geodetic coordinates \e lat, \e lon (degrees), \e h
00069      * (meters) to local cartesian coordinates \e x, \e y, \e z (meters).  \e
00070      * lat should be in the range [-90, 90]; \e lon and \e lon0 should be in
00071      * the range [-180, 360].
00072      **********************************************************************/
00073     void Forward(double lat, double lon, double h,
00074                  double& x, double& y, double& z) const throw();
00075 
00076     /**
00077      * Convert from local cartesian \e x, \e y, \e z (meters) to geodetic
00078      * coordinates \e lat, \e lon (degrees), \e h (meters).  The value of \e
00079      * lon returned is in the range [-180, 180).
00080      **********************************************************************/
00081     void Reverse(double x, double y, double z,
00082                  double& lat, double& lon, double& h) const throw();
00083 
00084     /**
00085      * Return the latitude of the origin (degrees).
00086      **********************************************************************/
00087     double LatitudeOrigin() const throw() { return _lat0; }
00088 
00089     /**
00090      * Return the longitude of the origin (degrees).
00091      **********************************************************************/
00092     double LongitudeOrigin() const throw() { return _lon0; }
00093 
00094     /**
00095      * Return the height of the origin (meters).
00096      **********************************************************************/
00097     double HeightOrigin() const throw() { return _h0; }
00098   };
00099 
00100 } // namespace GeographicLib
00101 
00102 #endif