JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGLocation.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGLocation.h
4  Author: Jon S. Berndt, Mathias Froehlich
5  Date started: 04/04/2004
6 
7  ------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) ------------------
8  ------- (C) 2004 Mathias Froehlich (Mathias.Froehlich@web.de) ----
9  ------- (C) 2011 Ola Røer Thorsen (ola@silentwings.no) -----------
10 
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU Lesser General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15 
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19  details.
20 
21  You should have received a copy of the GNU Lesser General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA 02111-1307, USA.
24 
25  Further information about the GNU Lesser General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27 
28 HISTORY
29 -------------------------------------------------------------------------------
30 04/04/2004 MF Created from code previously in the old positions class.
31 11/01/2011 ORT Encapsulated ground callback code in FGLocation and removed
32  it from FGFDMExec.
33 
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 SENTRY
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 
38 #ifndef FGLOCATION_H
39 #define FGLOCATION_H
40 
41 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 INCLUDES
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 
45 #include "FGJSBBase.h"
46 #include "FGColumnVector3.h"
47 #include "FGMatrix33.h"
48 #include "input_output/FGGroundCallback.h"
49 
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 DEFINITIONS
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 
54 #define ID_LOCATION "$Id: FGLocation.h,v 1.35 2015/09/20 20:53:13 bcoconni Exp $"
55 
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 FORWARD DECLARATIONS
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 
60 namespace JSBSim {
61 
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 CLASS DOCUMENTATION
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 
156 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 CLASS DECLARATION
158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
159 
160 class FGLocation : public FGJSBBase
161 {
162 public:
164  FGLocation(void);
165 
171  FGLocation(double lon, double lat, double radius);
172 
177  FGLocation(const FGColumnVector3& lv);
178 
180  FGLocation(const FGLocation& l);
181 
190  void SetLongitude(double longitude);
191 
204  void SetLatitude(double latitude);
205 
217  void SetRadius(double radius);
218 
223  void SetPosition(double lon, double lat, double radius);
224 
229  void SetPositionGeodetic(double lon, double lat, double height);
230 
234  void SetEllipse(double semimajor, double semiminor);
235 
241  void SetEarthPositionAngle(double EPA) {epa = EPA; mCacheValid = false;}
242 
248  void IncrementEarthPositionAngle(double delta) {epa += delta; mCacheValid = false;}
249 
254  double GetLongitude() const { ComputeDerived(); return mLon; }
255 
260  double GetLongitudeDeg() const { ComputeDerived(); return radtodeg*mLon; }
261 
263  double GetSinLongitude() const { ComputeDerived(); return -mTec2l(2,1); }
264 
266  double GetCosLongitude() const { ComputeDerived(); return mTec2l(2,2); }
267 
272  double GetLatitude() const { ComputeDerived(); return mLat; }
273 
278  double GetGeodLatitudeRad(void) const { ComputeDerived(); return mGeodLat; }
279 
284  double GetLatitudeDeg() const { ComputeDerived(); return radtodeg*mLat; }
285 
290  double GetGeodLatitudeDeg(void) const { ComputeDerived(); return radtodeg*mGeodLat; }
291 
293  double GetGeodAltitude(void) const {ComputeDerived(); return GeodeticAltitude;}
294 
296  double GetSinLatitude() const { ComputeDerived(); return -mTec2l(3,3); }
297 
299  double GetCosLatitude() const { ComputeDerived(); return mTec2l(1,3); }
300 
302  double GetTanLatitude() const {
303  ComputeDerived();
304  double cLat = mTec2l(1,3);
305  if (cLat == 0.0)
306  return 0.0;
307  else
308  return -mTec2l(3,3)/cLat;
309  }
310 
316  double GetEPA() const {return epa;}
317 
322  //double GetRadius() const { return mECLoc.Magnitude(); } // may not work with FlightGear
323  double GetRadius() const { ComputeDerived(); return mRadius; }
324 
331 
335  void SetAltitudeASL(double altitudeASL)
336  { SetRadius(GetSeaLevelRadius() + altitudeASL); }
337 
341  void SetAltitudeAGL(double altitudeAGL)
342  { SetRadius(GetTerrainRadius() + altitudeAGL); }
343 
347  double GetSeaLevelRadius(void) const
348  { ComputeDerived(); return GroundCallback->GetSeaLevelRadius(*this); }
349 
353  double GetTerrainRadius(void) const
354  { ComputeDerived(); return GroundCallback->GetTerrainGeoCentRadius(*this); }
355 
359  double GetAltitudeASL(void) const
360  { ComputeDerived(); return GroundCallback->GetAltitude(*this); }
361 
365  double GetAltitudeAGL(void) const {
366  FGLocation c;
367  FGColumnVector3 n,v,w;
368  return GetContactPoint(c,n,v,w);
369  }
370 
378  double GetContactPoint(FGLocation& contact, FGColumnVector3& normal,
379  FGColumnVector3& v, FGColumnVector3& w) const
380  { ComputeDerived(); return GroundCallback->GetAGLevel(*this, contact, normal, v, w); }
382 
393  static void SetGroundCallback(FGGroundCallback* gc) { GroundCallback = gc; }
394 
404  static FGGroundCallback* GetGroundCallback(void) { return GroundCallback; }
405 
409  const FGMatrix33& GetTl2ec(void) const { ComputeDerived(); return mTl2ec; }
410 
414  const FGMatrix33& GetTec2l(void) const { ComputeDerived(); return mTec2l; }
415 
421  const FGMatrix33& GetTi2ec(void) const { ComputeDerived(); return mTi2ec; }
422 
428  const FGMatrix33& GetTec2i(void) const { ComputeDerived(); return mTec2i; }
429 
435  const FGMatrix33& GetTi2l(void) const {ComputeDerived(); return mTi2l;}
436 
442  const FGMatrix33& GetTl2i(void) const {ComputeDerived(); return mTl2i;}
443 
450  double GetDistanceTo(double target_longitude, double target_latitude) const;
451 
459  double GetHeadingTo(double target_longitude, double target_latitude) const;
460 
468  ComputeDerived(); return mTl2ec*lvec + mECLoc;
469  }
470 
478  ComputeDerived(); return mTec2l*(ecvec - mECLoc);
479  }
480 
481  // For time-stepping, locations have vector properties...
482 
488  double operator()(unsigned int idx) const { return mECLoc.Entry(idx); }
489 
495  double& operator()(unsigned int idx) { mCacheValid = false; return mECLoc.Entry(idx); }
496 
505  double Entry(unsigned int idx) const { return mECLoc.Entry(idx); }
506 
515  double& Entry(unsigned int idx) {
516  mCacheValid = false; return mECLoc.Entry(idx);
517  }
518 
526  {
527  mECLoc(eX) = v(eX);
528  mECLoc(eY) = v(eY);
529  mECLoc(eZ) = v(eZ);
530  mCacheValid = false;
531  //ComputeDerived();
532  return *this;
533  }
534 
538  const FGLocation& operator=(const FGLocation& l);
539 
542  bool operator==(const FGLocation& l) const {
543  return mECLoc == l.mECLoc;
544  }
545 
548  bool operator!=(const FGLocation& l) const { return ! operator==(l); }
549 
554  const FGLocation& operator+=(const FGLocation &l) {
555  mCacheValid = false;
556  mECLoc += l.mECLoc;
557  return *this;
558  }
559 
564  const FGLocation& operator-=(const FGLocation &l) {
565  mCacheValid = false;
566  mECLoc -= l.mECLoc;
567  return *this;
568  }
569 
574  const FGLocation& operator*=(double scalar) {
575  mCacheValid = false;
576  mECLoc *= scalar;
577  return *this;
578  }
579 
584  const FGLocation& operator/=(double scalar) {
585  return operator*=(1.0/scalar);
586  }
587 
591  FGLocation operator+(const FGLocation& l) const {
592  return FGLocation(mECLoc + l.mECLoc);
593  }
594 
598  FGLocation operator-(const FGLocation& l) const {
599  return FGLocation(mECLoc - l.mECLoc);
600  }
601 
606  FGLocation operator*(double scalar) const {
607  return FGLocation(scalar*mECLoc);
608  }
609 
611  operator const FGColumnVector3&() const {
612  return mECLoc;
613  }
614 
615 private:
619  void ComputeDerivedUnconditional(void) const;
620 
625  void ComputeDerived(void) const {
626  if (!mCacheValid)
627  ComputeDerivedUnconditional();
628  }
629 
639  FGColumnVector3 mECLoc;
640 
642  mutable double mLon;
643  mutable double mLat;
644  mutable double mRadius;
645  mutable double mGeodLat;
646  mutable double GeodeticAltitude;
647 
649  mutable FGMatrix33 mTl2ec;
650  mutable FGMatrix33 mTec2l;
651  mutable FGMatrix33 mTi2ec;
652  mutable FGMatrix33 mTec2i;
653  mutable FGMatrix33 mTi2l;
654  mutable FGMatrix33 mTl2i;
655 
656  double epa;
657 
658  /* Terms for geodetic latitude calculation. Values are from WGS84 model */
659  double a; // Earth semimajor axis in feet
660  double e2; // Earth eccentricity squared
661  double c;
662  double ec;
663  double ec2;
664 
671  mutable bool mCacheValid;
672 
674  static FGGroundCallback_ptr GroundCallback;
675 };
676 
683 inline FGLocation operator*(double scalar, const FGLocation& l)
684 {
685  return l.operator*(scalar);
686 }
687 
688 } // namespace JSBSim
689 
690 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 #endif
bool operator==(const FGLocation &l) const
This operator returns true if the ECEF location vectors for the two location objects are equal...
Definition: FGLocation.h:542
static void SetGroundCallback(FGGroundCallback *gc)
Sets the ground callback pointer.
Definition: FGLocation.h:393
void SetPosition(double lon, double lat, double radius)
Sets the longitude, latitude and the distance from the center of the earth.
Definition: FGLocation.cpp:254
const FGLocation & operator*=(double scalar)
This operator scales the ECEF position vector.
Definition: FGLocation.h:574
void SetLongitude(double longitude)
Set the longitude.
Definition: FGLocation.cpp:197
double GetSeaLevelRadius(void) const
Get the local sea level radius.
Definition: FGLocation.h:347
void SetLatitude(double latitude)
Set the latitude.
Definition: FGLocation.cpp:217
double GetAltitudeASL(void) const
Get the altitude above sea level.
Definition: FGLocation.h:359
void SetAltitudeAGL(double altitudeAGL)
Set the altitude above ground level.
Definition: FGLocation.h:341
void SetRadius(double radius)
Set the distance from the center of the earth.
Definition: FGLocation.cpp:241
double GetGeodAltitude(void) const
Gets the geodetic altitude in feet.
Definition: FGLocation.h:293
double GetSinLatitude() const
Get the sine of Latitude.
Definition: FGLocation.h:296
double GetGeodLatitudeDeg(void) const
Get the geodetic latitude in degrees.
Definition: FGLocation.h:290
double GetDistanceTo(double target_longitude, double target_latitude) const
Get the geodetic distance between the current location and a given location.
Definition: FGLocation.cpp:418
double GetLatitude() const
Get the latitude.
Definition: FGLocation.h:272
This class provides callback slots to get ground specific data.
FGLocation holds an arbitrary location in the Earth centered Earth fixed reference frame (ECEF)...
Definition: FGLocation.h:160
FGColumnVector3 LocationToLocal(const FGColumnVector3 &ecvec) const
Conversion from a location in the earth centered and fixed frame to local horizontal frame coordinate...
Definition: FGLocation.h:477
FGLocation operator+(const FGLocation &l) const
This operator adds two ECEF position vectors.
Definition: FGLocation.h:591
double GetContactPoint(FGLocation &contact, FGColumnVector3 &normal, FGColumnVector3 &v, FGColumnVector3 &w) const
Get terrain contact point information below the current location.
Definition: FGLocation.h:378
double GetCosLongitude() const
Get the cosine of Longitude.
Definition: FGLocation.h:266
FGLocation operator*(double scalar) const
This operator scales an ECEF position vector.
Definition: FGLocation.h:606
void SetPositionGeodetic(double lon, double lat, double height)
Sets the longitude, latitude and the distance above the reference ellipsoid.
Definition: FGLocation.cpp:270
double GetEPA() const
Return the Earth Position Angle.
Definition: FGLocation.h:316
void SetEarthPositionAngle(double EPA)
Sets the Earth position angle.
Definition: FGLocation.h:241
double GetRadius() const
Get the distance from the center of the earth.
Definition: FGLocation.h:323
void SetEllipse(double semimajor, double semiminor)
Sets the semimajor and semiminor axis lengths for this planet.
Definition: FGLocation.cpp:285
double Entry(unsigned int idx) const
Read access the entries of the vector.
Definition: FGLocation.h:505
const FGLocation & operator=(const FGColumnVector3 &v)
Sets this location via the supplied vector.
Definition: FGLocation.h:525
const FGMatrix33 & GetTi2ec(void) const
Transform matrix from inertial to earth centered frame.
Definition: FGLocation.h:421
double GetLongitude() const
Get the longitude.
Definition: FGLocation.h:254
double & Entry(unsigned int idx)
Write access the entries of the vector.
Definition: FGLocation.h:515
void SetAltitudeASL(double altitudeASL)
Set the altitude above sea level.
Definition: FGLocation.h:335
const FGLocation & operator/=(double scalar)
This operator scales the ECEF position vector.
Definition: FGLocation.h:584
double GetTanLatitude() const
Get the cosine of Latitude.
Definition: FGLocation.h:302
JSBSim Base class.
Definition: FGJSBBase.h:80
double Entry(const unsigned int idx) const
Read access the entries of the vector.
FGLocation LocalToLocation(const FGColumnVector3 &lvec) const
Conversion from Local frame coordinates to a location in the earth centered and fixed frame...
Definition: FGLocation.h:467
double GetHeadingTo(double target_longitude, double target_latitude) const
Get the heading that should be followed from the current location to a given location along the short...
Definition: FGLocation.cpp:447
double GetTerrainRadius(void) const
Get the local terrain radius.
Definition: FGLocation.h:353
const FGLocation & operator+=(const FGLocation &l)
This operator adds the ECEF position vectors.
Definition: FGLocation.h:554
const FGMatrix33 & GetTl2i(void) const
Transform matrix from local horizontal to inertial frame.
Definition: FGLocation.h:442
FGLocation(void)
Default constructor.
Definition: FGLocation.cpp:60
This class implements a 3 element column vector.
double operator()(unsigned int idx) const
Read access the entries of the vector.
Definition: FGLocation.h:488
double GetSinLongitude() const
Get the sine of Longitude.
Definition: FGLocation.h:263
double GetGeodLatitudeRad(void) const
Get the geodetic latitude.
Definition: FGLocation.h:278
double GetLongitudeDeg() const
Get the longitude.
Definition: FGLocation.h:260
double GetCosLatitude() const
Get the cosine of Latitude.
Definition: FGLocation.h:299
const FGMatrix33 & GetTec2l(void) const
Transform matrix from the earth centered to local horizontal frame.
Definition: FGLocation.h:414
Handles matrix math operations.
Definition: FGMatrix33.h:92
double GetLatitudeDeg() const
Get the latitude.
Definition: FGLocation.h:284
FGLocation operator-(const FGLocation &l) const
This operator substracts two ECEF position vectors.
Definition: FGLocation.h:598
static FGGroundCallback * GetGroundCallback(void)
Get a pointer to the ground callback currently used.
Definition: FGLocation.h:404
const FGMatrix33 & GetTec2i(void) const
Transform matrix from the earth centered to inertial frame.
Definition: FGLocation.h:428
const FGLocation & operator-=(const FGLocation &l)
This operator substracts the ECEF position vectors.
Definition: FGLocation.h:564
const FGMatrix33 & GetTl2ec(void) const
Transform matrix from local horizontal to earth centered frame.
Definition: FGLocation.h:409
const FGMatrix33 & GetTi2l(void) const
Transform matrix from the inertial to local horizontal frame.
Definition: FGLocation.h:435
double & operator()(unsigned int idx)
Write access the entries of the vector.
Definition: FGLocation.h:495
void IncrementEarthPositionAngle(double delta)
Increments the Earth position angle.
Definition: FGLocation.h:248
bool operator!=(const FGLocation &l) const
This operator returns true if the ECEF location vectors for the two location objects are not equal...
Definition: FGLocation.h:548
double GetAltitudeAGL(void) const
Get the altitude above ground level.
Definition: FGLocation.h:365