Position.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: Position.hpp 1951 2009-06-18 07:14:41Z coandrei $"
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00034 //  
00035 //  Copyright 2004, The University of Texas at Austin
00036 //
00037 //============================================================================
00038 
00039 #include "Exception.hpp"
00040 #include "StringUtils.hpp"
00041 #include "DayTime.hpp"  // for FormatException
00042 #include "Triple.hpp"
00043 #include "GeoidModel.hpp"
00044 #include "Xvt.hpp"
00045 
00046 namespace gpstk
00047 {
00050 
00051       // The following forward declaration of Position and range are the only
00052       // way I can get range to be a member of namespace gpstk.
00053    class Position;
00054    double range(const Position& A, const Position& B) throw(GeometryException);
00055    
00118    class Position : public Triple
00119    {
00120    public:
00121       // ----------- Part  1: coordinate systems --------------------------------
00122       //
00124       enum CoordinateSystem
00125       {
00126          Unknown=0,  
00127          Geodetic,   
00128          Geocentric, 
00129          Cartesian,  
00130          Spherical   
00131       };
00132 
00134       std::string getSystemName()
00135          throw();
00136 
00137       // ----------- Part  2: member functions: tolerance -----------------------
00138       //
00140       static const double ONE_MM_TOLERANCE;
00142       static const double ONE_CM_TOLERANCE;
00144       static const double ONE_UM_TOLERANCE;
00145       
00147       static double POSITION_TOLERANCE;
00148 
00150       static double setPositionTolerance(const double tol)
00151          { POSITION_TOLERANCE = tol;  return POSITION_TOLERANCE; }
00152 
00154       static double getPositionTolerance()
00155          { return POSITION_TOLERANCE; }
00156    
00164       Position& setTolerance(const double tol)
00165          throw();
00166 
00167       // ----------- Part  3: member functions: constructors --------------------
00168       //
00173       Position()
00174          throw();
00175 
00187       Position(const double& a,
00188                const double& b,
00189                const double& c,
00190                CoordinateSystem s = Cartesian,
00191                GeoidModel *geoid = NULL)
00192          throw(GeometryException);
00193 
00203       Position(const double ABC[3],
00204                CoordinateSystem s = Cartesian,
00205                GeoidModel *geoid = NULL)
00206          throw(GeometryException);
00207 
00217       Position(const Triple& ABC,
00218                CoordinateSystem s = Cartesian,
00219                GeoidModel *geoid = NULL)
00220          throw(GeometryException);
00221 
00227       Position(const Xvt& xvt)
00228          throw();
00229 
00231       ~Position()
00232          throw()
00233          {}
00234 
00235       // ----------- Part  4: member functions: arithmetic ----------------------
00236       //
00243       Position& operator-=(const Position& right)
00244          throw();
00245 
00252       Position& operator+=(const Position& right)
00253          throw();
00254 
00261       friend Position operator-(const Position& left,
00262                                       const Position& right)
00263          throw();
00264 
00271       friend Position operator+(const Position& left,
00272                                       const Position& right)
00273          throw();
00274 
00280       friend Position operator*(const double& scale,
00281                                 const Position& right)
00282          {
00283             Position tmp(right);
00284             tmp.theArray *= scale;
00285             return tmp;
00286          }
00287 
00293       friend Position operator*(const Position& left,
00294                                 const double& scale)
00295          {
00296             return operator*(scale, left);
00297          }
00298 
00304       friend Position operator*(const int& scale,
00305                                 const Position& right)
00306          {
00307             return operator*(double(scale), right);
00308          }
00309 
00315       friend Position operator*(const Position& left,
00316                                 const int& scale)
00317          {
00318             return operator*(double(scale), left);
00319          }
00320 
00321       // ----------- Part  5: member functions: comparisons ---------------------
00322       //
00327       bool operator==(const Position &right) const
00328          throw();
00329 
00334       bool operator!=(const Position &right) const
00335          throw();
00336 
00337       // ----------- Part  6: member functions: coordinate transformations ------
00338       //
00344       Position transformTo(CoordinateSystem sys)
00345          throw();
00346   
00349       Position asGeodetic()
00350          throw()
00351       { transformTo(Geodetic); return *this; }
00352 
00356       Position asGeodetic(GeoidModel *geoid)
00357          throw(GeometryException)
00358       {
00359          try { setGeoidModel(geoid); }
00360          catch(GeometryException& ge) { GPSTK_RETHROW(ge); }
00361          transformTo(Geodetic);
00362          return *this;
00363       }
00364 
00367       Position asECEF()
00368          throw()
00369       { transformTo(Cartesian); return *this; }
00370 
00371 
00372       // ----------- Part  7: member functions: get -----------------------------
00373       // 
00374       // These routines retrieve coordinate values in all coordinate systems.
00375       //
00377       double X() const
00378          throw();
00379 
00381       double Y() const
00382          throw();
00383 
00385       double Z() const
00386          throw();
00387 
00389       double geodeticLatitude() const
00390          throw();
00391 
00394       double geocentricLatitude() const
00395          throw();
00396 
00398       double theta() const
00399          throw();
00400 
00402       double phi() const
00403          throw();
00404 
00407       double longitude() const
00408          throw();
00409 
00412       double radius() const
00413          throw();
00414 
00416       double height() const
00417          throw();
00418 
00420       CoordinateSystem getCoordinateSystem() const
00421          throw() 
00422       { return system; };
00423 
00425       double getGeodeticLatitude() const
00426          throw()
00427       { return geodeticLatitude(); }
00428 
00430       double getGeocentricLatitude() const
00431          throw()
00432       { return geocentricLatitude(); }
00433 
00435       double getLongitude() const
00436          throw()
00437       { return longitude(); }
00438 
00440       double getAltitude() const
00441          throw()
00442       { return height(); }
00443 
00445       double getHeight() const
00446          throw()
00447       { return height(); }
00448 
00450       double getX() const
00451          throw()
00452       { return X(); }
00453 
00455       double getY() const
00456          throw()
00457       { return Y(); }
00458 
00460       double getZ() const
00461          throw()
00462       { return Z(); }
00463 
00465       double getTheta() const
00466          throw()
00467       { return theta(); }
00468 
00470       double getPhi() const
00471          throw()
00472       { return phi(); }
00473 
00475       double getRadius() const
00476          throw()
00477       { return radius(); }
00478 
00479       // ----------- Part  8: member functions: set -----------------------------
00480       //
00486       void setGeoidModel(const GeoidModel *geoid)
00487          throw(GeometryException);
00488 
00497       Position& setGeodetic(const double lat,
00498                             const double lon,
00499                             const double ht,
00500                             const GeoidModel *geoid = NULL)
00501          throw(GeometryException);
00502 
00511       Position& setGeocentric(const double lat,
00512                               const double lon,
00513                               const double rad)
00514          throw(GeometryException);
00515 
00524       Position& setSpherical(const double theta,
00525                              const double phi,
00526                              const double rad)
00527          throw(GeometryException);
00528 
00536       Position& setECEF(const double X,
00537                         const double Y,
00538                         const double Z)
00539          throw();
00540 
00547       Position& setECEF(const double XYZ[3])
00548          throw()
00549       { return setECEF(XYZ[0],XYZ[1],XYZ[2]); }
00550 
00556       Position& setECEF(const Triple& XYZ)
00557          throw()
00558       { return setECEF(XYZ[0],XYZ[1],XYZ[2]); }
00559 
00560       // ----------- Part 9: member functions: setToString, printf -------------
00561       //
00612       Position& setToString(const std::string& str,
00613                             const std::string& fmt)
00614          throw(GeometryException,
00615                DayTime::FormatException,
00616                StringUtils::StringException);
00617 
00618 
00619          // if you can see this, ignore the \'s below, as they are for
00620          // the nasty html-ifying of doxygen.  Browsers try to
00621          // interpret the % and they get all messed up.
00653       std::string printf(const char *fmt) const
00654          throw(StringUtils::StringException);
00655 
00658       std::string printf(const std::string& fmt) const
00659          throw(StringUtils::StringException) 
00660       { return printf(fmt.c_str()); }
00661 
00663       std::string asString() const
00664          throw(StringUtils::StringException);
00665 
00666       // ----------- Part 10: functions: fundamental conversions ---------------
00667       // 
00673       static void convertSphericalToCartesian(const Triple& tpr,
00674                                               Triple& xyz)
00675          throw();
00676 
00683       static void convertCartesianToSpherical(const Triple& xyz,
00684                                               Triple& tpr)
00685          throw();
00686 
00687 
00698       static void convertCartesianToGeodetic(const Triple& xyz,
00699                                              Triple& llh,
00700                                              const double A,
00701                                              const double eccSq)
00702          throw();
00703 
00713       static void convertGeodeticToCartesian(const Triple& llh,
00714                                              Triple& xyz,
00715                                              const double A,
00716                                              const double eccSq)
00717          throw();
00718 
00719 
00726       static void convertCartesianToGeocentric(const Triple& xyz,
00727                                                Triple& llr)
00728          throw();
00729 
00734       static void convertGeocentricToCartesian(const Triple& llr,
00735                                                Triple& xyz)
00736          throw();
00737 
00738 
00746       static void convertGeocentricToGeodetic(const Triple& llr,
00747                                               Triple& geodeticllh,
00748                                               const double A,
00749                                               const double eccSq)
00750          throw();
00751 
00759       static void convertGeodeticToGeocentric(const Triple& geodeticllh,
00760                                               Triple& llr,
00761                                               const double A,
00762                                               const double eccSq)
00763          throw();
00764 
00765       // ----------- Part 11: operator<< and other useful functions -------------
00766       //
00773       friend std::ostream& operator<<(std::ostream& s,
00774                                       const Position& p);
00775 
00784       friend double range(const Position& A,
00785                           const Position& B)
00786          throw(GeometryException);
00787 
00793       static double radiusEarth(const double geolat,
00794                                 const double A,
00795                                 const double eccSq)
00796          throw();
00797 
00803       double radiusEarth() const
00804          throw()
00805       {
00806          Position p(*this);
00807          p.transformTo(Position::Geodetic);
00808          return Position::radiusEarth(p.theArray[0], p.AEarth, p.eccSquared);
00809       }
00810 
00818       double elevation(const Position& Target) const
00819          throw(GeometryException);
00820 
00829       double elevationGeodetic(const Position& Target) const
00830          throw(GeometryException);
00831 
00839       double azimuth(const Position& Target) const
00840          throw(GeometryException);
00841 
00850       double azimuthGeodetic(const Position& Target) const
00851          throw(GeometryException);
00852 
00867       Position getIonosphericPiercePoint(const double elev,
00868                                          const double azim,
00869                                          const double ionoht) const
00870          throw();
00871 
00872       // ----------- Part 12: private functions and member data -----------------
00873       //
00874    private:
00875 
00884       void initialize(const double a,
00885                      const double b,
00886                      const double c,
00887                      CoordinateSystem s = Cartesian,
00888                      GeoidModel *geoid = NULL)
00889          throw(GeometryException);
00890 
00891          /* Values of the coordinates, defined for each system as follows;
00892          *    Cartesian  : X,Y,Z in meters
00893          *    Geocentric : Latitude(degrees N), Longitude(degrees E),
00894          *                    Radius (meters)
00895          *    Geodetic   : Latitude(degrees N), Longitude(degrees E),
00896          *                    Height above ellipsoid (meters)
00897          *    Spherical  : theta (degrees) - angle from the z axis
00898          *                 phi (degrees) - angle in xy plane from x axis toward
00899          *                                     y axis (same as longitude)
00900          *                 radius (meters?) - distance from origin
00901          */
00902       // use std::valarray<double> theArray;  -- inherit from Triple
00903 
00905       double AEarth;
00906 
00908       double eccSquared;
00909 
00911       CoordinateSystem system;
00912 
00914       double tolerance;
00915 
00916    };   // end class Position
00917 
00919 
00920 }  // namespace gpstk
00921 
00922 #endif   // GPSTK_POSITION_HPP

Generated on Wed Feb 8 03:31:01 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1