JSBSim Flight Dynamics Model  1.2.1 (08 Aug 2024)
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
13  Software Foundation; either version 2 of the License, or (at your option) any
14  later 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
22  with this program; if not, write to the Free Software Foundation, Inc., 59
23  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 
25  Further information about the GNU Lesser General Public License can also be
26  found on 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 <cassert>
46 
47 #include "FGJSBBase.h"
48 #include "FGColumnVector3.h"
49 #include "FGMatrix33.h"
50 
51 /* Setting the -ffast-math compilation flag is highly discouraged */
52 #ifdef __FAST_MATH__
53 #error Usage of -ffast-math is strongly discouraged
54 #endif
55 
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 FORWARD DECLARATIONS
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 
60 namespace JSBSim {
61 
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 CLASS DOCUMENTATION
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 
147 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 CLASS DECLARATION
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
150 
151 class JSBSIM_API FGLocation : public FGJSBBase
152 {
153 public:
155  FGLocation(void);
156 
162  FGLocation(double lon, double lat, double radius);
163 
168  FGLocation(const FGColumnVector3& lv);
169 
171  FGLocation(const FGLocation& l);
172 
184  void SetLongitude(double longitude);
185 
197  void SetLatitude(double latitude);
198 
209  void SetRadius(double radius);
210 
215  void SetPosition(double lon, double lat, double radius);
216 
221  void SetPositionGeodetic(double lon, double lat, double height);
222 
228  void SetEllipse(double semimajor, double semiminor);
229 
234  double GetLongitude() const { ComputeDerived(); return mLon; }
235 
240  double GetLongitudeDeg() const { ComputeDerived(); return radtodeg*mLon; }
241 
243  double GetSinLongitude() const { ComputeDerived(); return -mTec2l(2,1); }
244 
246  double GetCosLongitude() const { ComputeDerived(); return mTec2l(2,2); }
247 
252  double GetLatitude() const { ComputeDerived(); return mLat; }
253 
258  double GetGeodLatitudeRad(void) const {
259  assert(mEllipseSet);
260  ComputeDerived(); return mGeodLat;
261  }
262 
267  double GetLatitudeDeg() const { ComputeDerived(); return radtodeg*mLat; }
268 
273  double GetGeodLatitudeDeg(void) const {
274  assert(mEllipseSet);
275  ComputeDerived(); return radtodeg*mGeodLat;
276  }
277 
279  double GetGeodAltitude(void) const {
280  assert(mEllipseSet);
281  ComputeDerived(); return GeodeticAltitude;
282  }
283 
285  double GetSeaLevelRadius(void) const;
286 
291  double GetRadius() const { ComputeDerived(); return mRadius; }
292 
296  const FGMatrix33& GetTl2ec(void) const { ComputeDerived(); return mTl2ec; }
297 
301  const FGMatrix33& GetTec2l(void) const { ComputeDerived(); return mTec2l; }
302 
309  double GetDistanceTo(double target_longitude, double target_latitude) const;
310 
318  double GetHeadingTo(double target_longitude, double target_latitude) const;
319 
327  ComputeDerived(); return mTl2ec*lvec + mECLoc;
328  }
329 
337  ComputeDerived(); return mTec2l*(ecvec - mECLoc);
338  }
339 
340  // For time-stepping, locations have vector properties...
341 
347  double operator()(unsigned int idx) const { return mECLoc.Entry(idx); }
348 
354  double& operator()(unsigned int idx) { mCacheValid = false; return mECLoc.Entry(idx); }
355 
364  double Entry(unsigned int idx) const { return mECLoc.Entry(idx); }
365 
374  double& Entry(unsigned int idx) {
375  mCacheValid = false; return mECLoc.Entry(idx);
376  }
377 
385  {
386  mECLoc(eX) = v(eX);
387  mECLoc(eY) = v(eY);
388  mECLoc(eZ) = v(eZ);
389  mCacheValid = false;
390  //ComputeDerived();
391  return *this;
392  }
393 
397  FGLocation& operator=(const FGLocation& l);
398 
401  bool operator==(const FGLocation& l) const {
402  return mECLoc == l.mECLoc;
403  }
404 
407  bool operator!=(const FGLocation& l) const { return ! operator==(l); }
408 
413  const FGLocation& operator+=(const FGLocation &l) {
414  mCacheValid = false;
415  mECLoc += l.mECLoc;
416  return *this;
417  }
418 
423  const FGLocation& operator-=(const FGLocation &l) {
424  mCacheValid = false;
425  mECLoc -= l.mECLoc;
426  return *this;
427  }
428 
433  const FGLocation& operator*=(double scalar) {
434  mCacheValid = false;
435  mECLoc *= scalar;
436  return *this;
437  }
438 
443  const FGLocation& operator/=(double scalar) {
444  return operator*=(1.0/scalar);
445  }
446 
450  FGLocation operator+(const FGLocation& l) const {
451  FGLocation result(mECLoc + l.mECLoc);
452  if (mEllipseSet) result.SetEllipse(a, ec*a);
453  return result;
454  }
455 
459  FGLocation operator-(const FGLocation& l) const {
460  FGLocation result(mECLoc - l.mECLoc);
461  if (mEllipseSet) result.SetEllipse(a, ec*a);
462  return result;
463  }
464 
469  FGLocation operator*(double scalar) const {
470  FGLocation result(scalar*mECLoc);
471  if (mEllipseSet) result.SetEllipse(a, ec*a);
472  return result;
473  }
474 
476  operator const FGColumnVector3&() const {
477  return mECLoc;
478  }
479 
480 private:
484  void ComputeDerivedUnconditional(void) const;
485 
490  void ComputeDerived(void) const {
491  if (!mCacheValid)
492  ComputeDerivedUnconditional();
493  }
494 
504  FGColumnVector3 mECLoc;
505 
507  mutable double mLon;
508  mutable double mLat;
509  mutable double mRadius;
510  mutable double mGeodLat;
511  mutable double GeodeticAltitude;
512 
514  mutable FGMatrix33 mTl2ec;
515  mutable FGMatrix33 mTec2l;
516 
517  /* Terms for geodetic latitude calculation. Values are from WGS84 model */
518  double a; // Earth semimajor axis in feet
519  double e2; // Earth eccentricity squared
520  double c;
521  double ec;
522  double ec2;
523 
530  mutable bool mCacheValid;
531  // Flag that checks that geodetic methods are called after SetEllipse() has
532  // been called.
533  bool mEllipseSet = false;
534 };
535 
542 inline FGLocation operator*(double scalar, const FGLocation& l)
543 {
544  return l.operator*(scalar);
545 }
546 
547 } // namespace JSBSim
548 
549 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
550 #endif
This class implements a 3 element column vector.
JSBSim Base class.
Definition: FGJSBBase.h:118
FGLocation holds an arbitrary location in the Earth centered Earth fixed reference frame (ECEF).
Definition: FGLocation.h:152
void SetEllipse(double semimajor, double semiminor)
Sets the semimajor and semiminor axis lengths for this planet.
Definition: FGLocation.cpp:259
FGLocation operator*(double scalar) const
This operator scales an ECEF position vector.
Definition: FGLocation.h:469
const FGMatrix33 & GetTl2ec(void) const
Transform matrix from local horizontal to earth centered frame.
Definition: FGLocation.h:296
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:407
const FGLocation & operator-=(const FGLocation &l)
This operator substracts the ECEF position vectors.
Definition: FGLocation.h:423
FGLocation operator+(const FGLocation &l) const
This operator adds two ECEF position vectors.
Definition: FGLocation.h:450
double GetCosLongitude() const
Get the cosine of Longitude.
Definition: FGLocation.h:246
const FGLocation & operator*=(double scalar)
This operator scales the ECEF position vector.
Definition: FGLocation.h:433
double operator()(unsigned int idx) const
Read access the entries of the vector.
Definition: FGLocation.h:347
double GetLatitude() const
Get the GEOCENTRIC latitude in radians.
Definition: FGLocation.h:252
const FGMatrix33 & GetTec2l(void) const
Transform matrix from the earth centered to local horizontal frame.
Definition: FGLocation.h:301
const FGLocation & operator=(const FGColumnVector3 &v)
Sets this location via the supplied vector.
Definition: FGLocation.h:384
const FGLocation & operator/=(double scalar)
This operator scales the ECEF position vector.
Definition: FGLocation.h:443
double GetSinLongitude() const
Get the sine of Longitude.
Definition: FGLocation.h:243
double GetGeodLatitudeRad(void) const
Get the GEODETIC latitude in radians.
Definition: FGLocation.h:258
double GetGeodLatitudeDeg(void) const
Get the GEODETIC latitude in degrees.
Definition: FGLocation.h:273
double & Entry(unsigned int idx)
Write access the entries of the vector.
Definition: FGLocation.h:374
double GetLongitude() const
Get the longitude.
Definition: FGLocation.h:234
const FGLocation & operator+=(const FGLocation &l)
This operator adds the ECEF position vectors.
Definition: FGLocation.h:413
double GetRadius() const
Get the distance from the center of the earth in feet.
Definition: FGLocation.h:291
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:336
FGLocation LocalToLocation(const FGColumnVector3 &lvec) const
Conversion from Local frame coordinates to a location in the earth centered and fixed frame.
Definition: FGLocation.h:326
FGLocation operator-(const FGLocation &l) const
This operator substracts two ECEF position vectors.
Definition: FGLocation.h:459
double GetLatitudeDeg() const
Get the GEOCENTRIC latitude in degrees.
Definition: FGLocation.h:267
double GetLongitudeDeg() const
Get the longitude.
Definition: FGLocation.h:240
double GetGeodAltitude(void) const
Gets the geodetic altitude in feet.
Definition: FGLocation.h:279
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:401
double & operator()(unsigned int idx)
Write access the entries of the vector.
Definition: FGLocation.h:354
double Entry(unsigned int idx) const
Read access the entries of the vector.
Definition: FGLocation.h:364
Handles matrix math operations.
Definition: FGMatrix33.h:70