Position.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: Position.hpp 3143 2012-06-19 16:19:50Z snelsen $"
00002 
00003 
00004 
00014 #ifndef GPSTK_POSITION_HPP
00015 #define GPSTK_POSITION_HPP
00016 
00017 //============================================================================
00018 //
00019 //  This file is part of GPSTk, the GPS Toolkit.
00020 //
00021 //  The GPSTk is free software; you can redistribute it and/or modify
00022 //  it under the terms of the GNU Lesser General Public License as published
00023 //  by the Free Software Foundation; either version 2.1 of the License, or
00024 //  any later version.
00025 //
00026 //  The GPSTk is distributed in the hope that it will be useful,
00027 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00028 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00029 //  GNU Lesser General Public License for more details.
00030 //
00031 //  You should have received a copy of the GNU Lesser General Public
00032 //  License along with GPSTk; if not, write to the Free Software Foundation,
00033 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00034 //  
00035 //  Copyright 2004, The University of Texas at Austin
00036 //
00037 //============================================================================
00038 
00039 #include "Exception.hpp"
00040 #include "StringUtils.hpp"
00041 #include "Triple.hpp"
00042 #include "EllipsoidModel.hpp"
00043 #include "ReferenceFrame.hpp"
00044 #include "Xvt.hpp"
00045 
00046 namespace gpstk
00047 {
00050 
00051       // forward declarations
00052    class Position;
00053    double range(const Position& A, const Position& B) throw(GeometryException);
00054    
00117    class Position : public Triple
00118    {
00119    public:
00120       // ----------- Part  1: coordinate systems --------------------------------
00121       //
00123       enum CoordinateSystem
00124       {
00125          Unknown=0,  
00126          Geodetic,   
00127          Geocentric, 
00128          Cartesian,  
00129          Spherical   
00130       };
00131 
00133       std::string getSystemName()
00134          throw();
00135 
00136       // ----------- Part  2: member functions: tolerance -----------------------
00137       //
00139       static const double ONE_MM_TOLERANCE;
00141       static const double ONE_CM_TOLERANCE;
00143       static const double ONE_UM_TOLERANCE;
00144       
00146       static double POSITION_TOLERANCE;
00147 
00149       static double setPositionTolerance(const double tol)
00150          { POSITION_TOLERANCE = tol;  return POSITION_TOLERANCE; }
00151 
00153       static double getPositionTolerance()
00154          { return POSITION_TOLERANCE; }
00155    
00163       Position& setTolerance(const double tol)
00164          throw();
00165 
00166       // ----------- Part  3: member functions: constructors --------------------
00167       //
00172       Position()
00173          throw();
00174 
00186       Position(const double& a,
00187                const double& b,
00188                const double& c,
00189                CoordinateSystem s = Cartesian,
00190                EllipsoidModel *ell = NULL,
00191                ReferenceFrame frame = ReferenceFrame::Unknown)
00192          throw(GeometryException);
00193 
00203       Position(const double ABC[3],
00204                CoordinateSystem s = Cartesian,
00205                EllipsoidModel *ell = NULL,
00206                ReferenceFrame frame = ReferenceFrame::Unknown)
00207          throw(GeometryException);
00208 
00218       Position(const Triple& ABC,
00219                CoordinateSystem s = Cartesian,
00220                EllipsoidModel *ell = NULL,
00221                ReferenceFrame frame = ReferenceFrame::Unknown)
00222          throw(GeometryException);
00223 
00229       Position(const Xvt& xvt)
00230          throw();
00231 
00233       ~Position()
00234          throw()
00235          {}
00236 
00237       // ----------- Part  4: member functions: arithmetic ----------------------
00238       //
00245       Position& operator-=(const Position& right)
00246          throw();
00247 
00254       Position& operator+=(const Position& right)
00255          throw();
00256 
00263       friend Position operator-(const Position& left,
00264                                       const Position& right)
00265          throw();
00266 
00273       friend Position operator+(const Position& left,
00274                                       const Position& right)
00275          throw();
00276 
00282       friend Position operator*(const double& scale,
00283                                 const Position& right)
00284          {
00285             Position tmp(right);
00286             tmp.theArray *= scale;
00287             return tmp;
00288          }
00289 
00295       friend Position operator*(const Position& left,
00296                                 const double& scale)
00297          {
00298             return operator*(scale, left);
00299          }
00300 
00306       friend Position operator*(const int& scale,
00307                                 const Position& right)
00308          {
00309             return operator*(double(scale), right);
00310          }
00311 
00317       friend Position operator*(const Position& left,
00318                                 const int& scale)
00319          {
00320             return operator*(double(scale), left);
00321          }
00322 
00323       // ----------- Part  5: member functions: comparisons ---------------------
00324       //
00329       bool operator==(const Position &right) const
00330          throw();
00331 
00336       bool operator!=(const Position &right) const
00337          throw();
00338 
00339       // ----------- Part  6: member functions: coordinate transformations ------
00340       //
00346       Position transformTo(CoordinateSystem sys)
00347          throw();
00348   
00351       Position asGeodetic()
00352          throw()
00353       { transformTo(Geodetic); return *this; }
00354 
00358       Position asGeodetic(EllipsoidModel *ell)
00359          throw(GeometryException)
00360       {
00361          try { setEllipsoidModel(ell); }
00362          catch(GeometryException& ge) { GPSTK_RETHROW(ge); }
00363          transformTo(Geodetic);
00364          return *this;
00365       }
00366 
00369       Position asECEF()
00370          throw()
00371       { transformTo(Cartesian); return *this; }
00372 
00373 
00374       // ----------- Part  7: member functions: get -----------------------------
00375       // 
00376       // These routines retrieve coordinate values in all coordinate systems.
00377       //
00378 
00380       const ReferenceFrame& getReferenceFrame() const
00381          throw();
00382       
00384       double X() const
00385          throw();
00386 
00388       double Y() const
00389          throw();
00390 
00392       double Z() const
00393          throw();
00394 
00396       double geodeticLatitude() const
00397          throw();
00398 
00401       double geocentricLatitude() const
00402          throw();
00403 
00405       double theta() const
00406          throw();
00407 
00409       double phi() const
00410          throw();
00411 
00414       double longitude() const
00415          throw();
00416 
00419       double radius() const
00420          throw();
00421 
00423       double height() const
00424          throw();
00425 
00427       CoordinateSystem getCoordinateSystem() const
00428          throw() 
00429       { return system; };
00430 
00432       double getGeodeticLatitude() const
00433          throw()
00434       { return geodeticLatitude(); }
00435 
00437       double getGeocentricLatitude() const
00438          throw()
00439       { return geocentricLatitude(); }
00440 
00442       double getLongitude() const
00443          throw()
00444       { return longitude(); }
00445 
00447       double getAltitude() const
00448          throw()
00449       { return height(); }
00450 
00452       double getHeight() const
00453          throw()
00454       { return height(); }
00455 
00457       double getX() const
00458          throw()
00459       { return X(); }
00460 
00462       double getY() const
00463          throw()
00464       { return Y(); }
00465 
00467       double getZ() const
00468          throw()
00469       { return Z(); }
00470 
00472       double getTheta() const
00473          throw()
00474       { return theta(); }
00475 
00477       double getPhi() const
00478          throw()
00479       { return phi(); }
00480 
00482       double getRadius() const
00483          throw()
00484       { return radius(); }
00485 
00486       // ----------- Part  8: member functions: set -----------------------------
00487       //
00492       void setReferenceFrame(const ReferenceFrame& frame)
00493          throw();
00494 
00500       void setEllipsoidModel(const EllipsoidModel *ell)
00501          throw(GeometryException);
00502 
00511       Position& setGeodetic(const double lat,
00512                             const double lon,
00513                             const double ht,
00514                             const EllipsoidModel *ell = NULL)
00515          throw(GeometryException);
00516 
00525       Position& setGeocentric(const double lat,
00526                               const double lon,
00527                               const double rad)
00528          throw(GeometryException);
00529 
00538       Position& setSpherical(const double theta,
00539                              const double phi,
00540                              const double rad)
00541          throw(GeometryException);
00542 
00550       Position& setECEF(const double X,
00551                         const double Y,
00552                         const double Z)
00553          throw();
00554 
00561       Position& setECEF(const double XYZ[3])
00562          throw()
00563       { return setECEF(XYZ[0],XYZ[1],XYZ[2]); }
00564 
00570       Position& setECEF(const Triple& XYZ)
00571          throw()
00572       { return setECEF(XYZ[0],XYZ[1],XYZ[2]); }
00573 
00574       // ----------- Part 9: member functions: setToString, printf -------------
00575       //
00625       Position& setToString(const std::string& str,
00626                             const std::string& fmt)
00627          throw(GeometryException,
00628                StringUtils::StringException);
00629 
00630 
00631          // if you can see this, ignore the \'s below, as they are for
00632          // the nasty html-ifying of doxygen.  Browsers try to
00633          // interpret the % and they get all messed up.
00665       std::string printf(const char *fmt) const
00666          throw(StringUtils::StringException);
00667 
00670       std::string printf(const std::string& fmt) const
00671          throw(StringUtils::StringException) 
00672       { return printf(fmt.c_str()); }
00673 
00675       std::string asString() const
00676          throw(StringUtils::StringException);
00677 
00678       // ----------- Part 10: functions: fundamental conversions ---------------
00679       // 
00685       static void convertSphericalToCartesian(const Triple& tpr,
00686                                               Triple& xyz)
00687          throw();
00688 
00695       static void convertCartesianToSpherical(const Triple& xyz,
00696                                               Triple& tpr)
00697          throw();
00698 
00699 
00710       static void convertCartesianToGeodetic(const Triple& xyz,
00711                                              Triple& llh,
00712                                              const double A,
00713                                              const double eccSq)
00714          throw();
00715 
00725       static void convertGeodeticToCartesian(const Triple& llh,
00726                                              Triple& xyz,
00727                                              const double A,
00728                                              const double eccSq)
00729          throw();
00730 
00731 
00738       static void convertCartesianToGeocentric(const Triple& xyz,
00739                                                Triple& llr)
00740          throw();
00741 
00746       static void convertGeocentricToCartesian(const Triple& llr,
00747                                                Triple& xyz)
00748          throw();
00749 
00750 
00758       static void convertGeocentricToGeodetic(const Triple& llr,
00759                                               Triple& geodeticllh,
00760                                               const double A,
00761                                               const double eccSq)
00762          throw();
00763 
00771       static void convertGeodeticToGeocentric(const Triple& geodeticllh,
00772                                               Triple& llr,
00773                                               const double A,
00774                                               const double eccSq)
00775          throw();
00776 
00777       // ----------- Part 11: operator<< and other useful functions -------------
00778       //
00785       friend std::ostream& operator<<(std::ostream& s,
00786                                       const Position& p);
00787 
00796       friend double range(const Position& A,
00797                           const Position& B)
00798          throw(GeometryException);
00799 
00805       static double radiusEarth(const double geolat,
00806                                 const double A,
00807                                 const double eccSq)
00808          throw();
00809 
00815       double radiusEarth() const
00816          throw()
00817       {
00818          Position p(*this);
00819          p.transformTo(Position::Geodetic);
00820          return Position::radiusEarth(p.theArray[0], p.AEarth, p.eccSquared);
00821       }
00822 
00830       double elevation(const Position& Target) const
00831          throw(GeometryException);
00832 
00841       double elevationGeodetic(const Position& Target) const
00842          throw(GeometryException);
00843 
00851       double azimuth(const Position& Target) const
00852          throw(GeometryException);
00853 
00862       double azimuthGeodetic(const Position& Target) const
00863          throw(GeometryException);
00864 
00879       Position getIonosphericPiercePoint(const double elev,
00880                                          const double azim,
00881                                          const double ionoht) const
00882          throw();
00883 
00889       double getCurvMeridian() const
00890          throw();
00891 
00897       double getCurvPrimeVertical() const
00898          throw();
00899 
00900       // ----------- Part 12: private functions and member data -----------------
00901       //
00902    private:
00903 
00912       void initialize(const double a,
00913                      const double b,
00914                      const double c,
00915                      CoordinateSystem s = Cartesian,
00916                      EllipsoidModel *ell = NULL,
00917                      ReferenceFrame frame = ReferenceFrame::Unknown)
00918          throw(GeometryException);
00919 
00920          /* Values of the coordinates, defined for each system as follows;
00921          *    Cartesian  : X,Y,Z in meters
00922          *    Geocentric : Latitude(degrees N), Longitude(degrees E),
00923          *                    Radius (meters)
00924          *    Geodetic   : Latitude(degrees N), Longitude(degrees E),
00925          *                    Height above ellipsoid (meters)
00926          *    Spherical  : theta (degrees) - angle from the z axis
00927          *                 phi (degrees) - angle in xy plane from x axis toward
00928          *                                     y axis (same as longitude)
00929          *                 radius (meters?) - distance from origin
00930          */
00931       // use std::valarray<double> theArray;  -- inherit from Triple
00932 
00934       double AEarth;
00935 
00937       double eccSquared;
00938 
00940       CoordinateSystem system;
00941 
00943       double tolerance;
00944       
00945       ReferenceFrame refFrame;
00946 
00947    };   // end class Position
00948 
00950 
00951 }  // namespace gpstk
00952 
00953 #endif   // GPSTK_POSITION_HPP

Generated on Sun May 19 03:31:11 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1