JSBSim Flight Dynamics Model  1.2.1 (08 Aug 2024)
An Open Source Flight Dynamics and Control Software Library in C++
FGLocation Class Reference

Detailed Description

FGLocation holds an arbitrary location in the Earth centered Earth fixed reference frame (ECEF).

The coordinate frame ECEF has its center in the middle of the earth. The X-axis points from the center of the Earth towards a location with zero latitude and longitude on the Earth surface. The Y-axis points from the center of the Earth towards a location with zero latitude and 90 deg East longitude on the Earth surface. The Z-axis points from the Earth center to the geographic north pole.

This class provides access functions to set and get the location as either the simple X, Y and Z values in ft or longitude/latitude and the radial distance of the location from the Earth center.

It is common to associate a parent frame with a location. This frame is usually called the local horizontal frame or simply the local frame. It is also called the NED frame (North, East, Down), as well as the Navigation frame. This frame has its X/Y plane parallel to the surface of the Earth. The X-axis points towards north, the Y-axis points east and the Z-axis is normal to the reference spheroid (WGS84 for Earth).

Since the local frame is determined by the location (and NOT by the orientation of the vehicle IN any frame), this class also provides the rotation matrices required to transform from the Earth centered (ECEF) frame to the local horizontal frame and back. This class "owns" the transformations that go from the ECEF frame to and from the local frame. Again, this is because the ECEF, and local frames do not involve the actual orientation of the vehicle - only the location on the Earth surface. There are conversion functions for conversion of position vectors given in the one frame to positions in the other frame.

The Earth centered reference frame is NOT an inertial frame since it rotates with the Earth.

The cartesian coordinates (X,Y,Z) in the Earth centered frame are the master values. All other values are computed from these master values and are cached as long as the location is changed by access through a non-const member function. Values are cached to improve performance. It is best practice to work with a natural set of master values. Other parameters that are derived from these master values are calculated only when needed, and IF they are needed and calculated, then they are cached (stored and remembered) so they do not need to be re-calculated until the master values they are derived from are themselves changed (and become stale).

Accuracy and round off

Given,

  • that we model a vehicle near the Earth
  • that the Earth surface average radius is about 2*10^7, ft
  • that we use double values for the representation of the location

we have an accuracy of about

1e-16*2e7ft/1 = 2e-9 ft

left. This should be sufficient for our needs. Note that this is the same relative accuracy we would have when we compute directly with lon/lat/radius. For the radius value this is clear. For the lon/lat pair this is easy to see. Take for example KSFO located at about 37.61 deg north 122.35 deg west, which corresponds to 0.65642 rad north and 2.13541 rad west. Both values are of magnitude of about 1. But 1 ft corresponds to about 1/(2e7*2*pi) = 7.9577e-09 rad. So the left accuracy with this representation is also about 1*1e-16/7.9577e-09 = 1.2566e-08 which is of the same magnitude as the representation chosen here.

The advantage of this representation is that it is a linear space without singularities. The singularities are the north and south pole and most notably the non-steady jump at -pi to pi. It is harder to track this jump correctly especially when we need to work with error norms and derivatives of the equations of motion within the time-stepping code. Also, the rate of change is of the same magnitude for all components in this representation which is an advantage for numerical stability in implicit time-stepping.

Note: Both GEOCENTRIC and GEODETIC latitudes can be used. In order to get best matching relative to a map, geodetic latitude must be used.

See also
Stevens and Lewis, "Aircraft Control and Simulation", Second edition
W. C. Durham "Aircraft Dynamics & Control", section 2.2
Author
Mathias Froehlich

Definition at line 151 of file FGLocation.h.

#include <FGLocation.h>

+ Inheritance diagram for FGLocation:
+ Collaboration diagram for FGLocation:

Public Member Functions

 FGLocation (const FGColumnVector3 &lv)
 Constructor to initialize the location with the cartesian coordinates (X,Y,Z) contained in the input FGColumnVector3. More...
 
 FGLocation (const FGLocation &l)
 Copy constructor.
 
 FGLocation (double lon, double lat, double radius)
 Constructor to set the longitude, latitude and the distance from the center of the earth. More...
 
 FGLocation (void)
 Default constructor.
 
double & Entry (unsigned int idx)
 Write access the entries of the vector. More...
 
double Entry (unsigned int idx) const
 Read access the entries of the vector. More...
 
double GetCosLongitude () const
 Get the cosine of Longitude.
 
double GetDistanceTo (double target_longitude, double target_latitude) const
 Get the geodetic distance between the current location and a given location. More...
 
double GetGeodAltitude (void) const
 Gets the geodetic altitude in feet.
 
double GetGeodLatitudeDeg (void) const
 Get the GEODETIC latitude in degrees. More...
 
double GetGeodLatitudeRad (void) const
 Get the GEODETIC latitude in radians. More...
 
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 shortest path. More...
 
double GetLatitude () const
 Get the GEOCENTRIC latitude in radians. More...
 
double GetLatitudeDeg () const
 Get the GEOCENTRIC latitude in degrees. More...
 
double GetLongitude () const
 Get the longitude. More...
 
double GetLongitudeDeg () const
 Get the longitude. More...
 
double GetRadius () const
 Get the distance from the center of the earth in feet. More...
 
double GetSeaLevelRadius (void) const
 Get the sea level radius in feet below the current location.
 
double GetSinLongitude () const
 Get the sine of Longitude.
 
const FGMatrix33GetTec2l (void) const
 Transform matrix from the earth centered to local horizontal frame. More...
 
const FGMatrix33GetTl2ec (void) const
 Transform matrix from local horizontal to earth centered frame. More...
 
FGLocation LocalToLocation (const FGColumnVector3 &lvec) const
 Conversion from Local frame coordinates to a location in the earth centered and fixed frame. More...
 
FGColumnVector3 LocationToLocal (const FGColumnVector3 &ecvec) const
 Conversion from a location in the earth centered and fixed frame to local horizontal frame coordinates. More...
 
 operator const FGColumnVector3 & () const
 Cast to a simple 3d vector.
 
bool operator!= (const FGLocation &l) const
 This operator returns true if the ECEF location vectors for the two location objects are not equal.
 
double & operator() (unsigned int idx)
 Write access the entries of the vector. More...
 
double operator() (unsigned int idx) const
 Read access the entries of the vector. More...
 
FGLocation operator* (double scalar) const
 This operator scales an ECEF position vector. More...
 
const FGLocationoperator*= (double scalar)
 This operator scales the ECEF position vector. More...
 
FGLocation operator+ (const FGLocation &l) const
 This operator adds two ECEF position vectors. More...
 
const FGLocationoperator+= (const FGLocation &l)
 This operator adds the ECEF position vectors. More...
 
FGLocation operator- (const FGLocation &l) const
 This operator substracts two ECEF position vectors. More...
 
const FGLocationoperator-= (const FGLocation &l)
 This operator substracts the ECEF position vectors. More...
 
const FGLocationoperator/= (double scalar)
 This operator scales the ECEF position vector. More...
 
const FGLocationoperator= (const FGColumnVector3 &v)
 Sets this location via the supplied vector. More...
 
FGLocationoperator= (const FGLocation &l)
 Sets this location via the supplied location object. More...
 
bool operator== (const FGLocation &l) const
 This operator returns true if the ECEF location vectors for the two location objects are equal.
 
void SetEllipse (double semimajor, double semiminor)
 Sets the semimajor and semiminor axis lengths for this planet. More...
 
void SetLatitude (double latitude)
 Set the GEOCENTRIC latitude. More...
 
void SetLongitude (double longitude)
 Set the longitude. More...
 
void SetPosition (double lon, double lat, double radius)
 Sets the longitude, latitude and the distance from the center of the earth. More...
 
void SetPositionGeodetic (double lon, double lat, double height)
 Sets the longitude, latitude and the distance above the reference spheroid. More...
 
void SetRadius (double radius)
 Set the distance from the center of the earth. More...
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1 , eM , eN }
 Moments L, M, N.
 
enum  { eP = 1 , eQ , eR }
 Rates P, Q, R.
 
enum  { eU = 1 , eV , eW }
 Velocities U, V, W.
 
enum  { eX = 1 , eY , eZ }
 Positions X, Y, Z.
 
enum  { ePhi = 1 , eTht , ePsi }
 Euler angles Phi, Theta, Psi.
 
enum  { eDrag = 1 , eSide , eLift }
 Stability axis forces, Drag, Side force, Lift.
 
enum  { eRoll = 1 , ePitch , eYaw }
 Local frame orientation Roll, Pitch, Yaw.
 
enum  { eNorth = 1 , eEast , eDown }
 Local frame position North, East, Down.
 
enum  { eLat = 1 , eLong , eRad }
 Locations Radius, Latitude, Longitude.
 
enum  {
  inNone = 0 , inDegrees , inRadians , inMeters ,
  inFeet
}
 Conversion specifiers.
 
- Static Public Member Functions inherited from FGJSBBase
static const std::string & GetVersion (void)
 Returns the version number of JSBSim. More...
 
static constexpr double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit. More...
 
static constexpr double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine. More...
 
static constexpr double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius. More...
 
static constexpr double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine. More...
 
static constexpr double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin. More...
 
static constexpr double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius. More...
 
static constexpr double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit. More...
 
static constexpr double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin. More...
 
static constexpr double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius. More...
 
static constexpr double FeetToMeters (double measure)
 Converts from feet to meters. More...
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison. More...
 
static constexpr double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static constexpr double sign (double num)
 
- Static Public Attributes inherited from FGJSBBase
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 
static short debug_lvl = 1
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Static Protected Attributes inherited from FGJSBBase
static constexpr double radtodeg = 180. / M_PI
 
static constexpr double degtorad = M_PI / 180.
 
static constexpr double hptoftlbssec = 550.0
 
static constexpr double psftoinhg = 0.014138
 
static constexpr double psftopa = 47.88
 
static constexpr double fttom = 0.3048
 
static constexpr double ktstofps = 1852./(3600*fttom)
 
static constexpr double fpstokts = 1.0 / ktstofps
 
static constexpr double inchtoft = 1.0/12.0
 
static constexpr double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static constexpr double in3tom3 = inchtoft*inchtoft*inchtoft/m3toft3
 
static constexpr double inhgtopa = 3386.38
 
static constexpr double slugtolb = 32.174049
 Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff. More...
 
static constexpr double lbtoslug = 1.0/slugtolb
 
static constexpr double kgtolb = 2.20462
 
static constexpr double kgtoslug = 0.06852168
 
static const std::string needed_cfg_version = "2.0"
 
static const std::string JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__
 

Constructor & Destructor Documentation

◆ FGLocation() [1/2]

FGLocation ( double  lon,
double  lat,
double  radius 
)

Constructor to set the longitude, latitude and the distance from the center of the earth.

Parameters
lonlongitude
latGEOCENTRIC latitude
radiusdistance from center of earth to vehicle in feet

Definition at line 71 of file FGLocation.cpp.

72  : mCacheValid(false)
73 {
74  e2 = c = 0.0;
75  a = ec = ec2 = 1.0;
76 
77  mLon = mLat = mRadius = 0.0;
78  mGeodLat = GeodeticAltitude = 0.0;
79 
80  mTl2ec.InitMatrix();
81  mTec2l.InitMatrix();
82 
83  double sinLat = sin(lat);
84  double cosLat = cos(lat);
85  double sinLon = sin(lon);
86  double cosLon = cos(lon);
87  mECLoc = { radius*cosLat*cosLon,
88  radius*cosLat*sinLon,
89  radius*sinLat };
90 }
void InitMatrix(void)
Initialize the matrix.
Definition: FGMatrix33.cpp:259
+ Here is the call graph for this function:

◆ FGLocation() [2/2]

FGLocation ( const FGColumnVector3 lv)

Constructor to initialize the location with the cartesian coordinates (X,Y,Z) contained in the input FGColumnVector3.

Distances are in feet, the position is expressed in the ECEF frame.

Parameters
lvvector that contain the cartesian coordinates

Definition at line 94 of file FGLocation.cpp.

95  : mECLoc(lv), mCacheValid(false)
96 {
97  e2 = c = 0.0;
98  a = ec = ec2 = 1.0;
99 
100  mLon = mLat = mRadius = 0.0;
101  mGeodLat = GeodeticAltitude = 0.0;
102 
103  mTl2ec.InitMatrix();
104  mTec2l.InitMatrix();
105 }
+ Here is the call graph for this function:

Member Function Documentation

◆ Entry() [1/2]

double& Entry ( unsigned int  idx)
inline

Write access the entries of the vector.

Parameters
idxthe component index.
Returns
a reference to the vector entry at the given index. Indices are counted starting with 1. This function is just a shortcut for the double& operator()(unsigned int idx) function. It is used internally to access the elements in a more convenient way. Note that the index given in the argument is unchecked.

Definition at line 374 of file FGLocation.h.

374  {
375  mCacheValid = false; return mECLoc.Entry(idx);
376  }
double Entry(const unsigned int idx) const
Read access the entries of the vector.

◆ Entry() [2/2]

double Entry ( unsigned int  idx) const
inline

Read access the entries of the vector.

Parameters
idxthe component index.
Returns
the value of the matrix entry at the given index. Indices are counted starting with 1. This function is just a shortcut for the double operator()(unsigned int idx) const function. It is used internally to access the elements in a more convenient way. Note that the index given in the argument is unchecked.

Definition at line 364 of file FGLocation.h.

364 { return mECLoc.Entry(idx); }

◆ GetDistanceTo()

double GetDistanceTo ( double  target_longitude,
double  target_latitude 
) const

Get the geodetic distance between the current location and a given location.

This corresponds to the shortest distance between the two locations. Earth curvature is taken into account.

Parameters
target_longitudethe target longitude in radians
target_latitudethe target geodetic latitude in radians
Returns
The geodetic distance in feet between the two locations

Definition at line 377 of file FGLocation.cpp.

379 {
380  assert(mEllipseSet);
381  ComputeDerived();
382  GeographicLib::Geodesic geod(a, 1 - ec);
383  GeographicLib::Math::real distance;
384  geod.Inverse(mGeodLat * radtodeg, mLon * radtodeg, target_latitude * radtodeg,
385  target_longitude * radtodeg, distance);
386 
387  return distance;
388 }

◆ GetGeodLatitudeDeg()

double GetGeodLatitudeDeg ( void  ) const
inline

Get the GEODETIC latitude in degrees.

Returns
the geodetic latitude in degrees of the location represented by this class instance. The returned value is in the range between -90 <= lon <= 90. Latitude is positive north and negative south.

Definition at line 273 of file FGLocation.h.

273  {
274  assert(mEllipseSet);
275  ComputeDerived(); return radtodeg*mGeodLat;
276  }

◆ GetGeodLatitudeRad()

double GetGeodLatitudeRad ( void  ) const
inline

Get the GEODETIC latitude in radians.

Returns
the geodetic latitude in rad of the location represented with this class instance. The returned values are in the range between -pi/2 <= lon <= pi/2. Latitude is positive north and negative south.

Definition at line 258 of file FGLocation.h.

258  {
259  assert(mEllipseSet);
260  ComputeDerived(); return mGeodLat;
261  }
+ Here is the caller graph for this function:

◆ GetHeadingTo()

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 shortest path.

Earth curvature is taken into account.

Parameters
target_longitudethe target longitude in radians
target_latitudethe target geodetic latitude in radians
Returns
The heading in radians that should be followed to reach the targeted location along the shortest path

Definition at line 392 of file FGLocation.cpp.

394 {
395  assert(mEllipseSet);
396  ComputeDerived();
397  GeographicLib::Geodesic geod(a, 1 - ec);
398  GeographicLib::Math::real heading, azimuth2;
399  geod.Inverse(mGeodLat * radtodeg, mLon * radtodeg, target_latitude * radtodeg,
400  target_longitude * radtodeg, heading, azimuth2);
401 
402  return heading * degtorad;
403 }

◆ GetLatitude()

double GetLatitude ( void  ) const
inline

Get the GEOCENTRIC latitude in radians.

Returns
the geocentric latitude in rad of the location represented with this class instance. The returned values are in the range between -pi/2 <= lon <= pi/2. Latitude is positive north and negative south.

Definition at line 252 of file FGLocation.h.

252 { ComputeDerived(); return mLat; }
+ Here is the caller graph for this function:

◆ GetLatitudeDeg()

double GetLatitudeDeg ( void  ) const
inline

Get the GEOCENTRIC latitude in degrees.

Returns
the geocentric latitude in deg of the location represented with this class instance. The returned value is in the range between -90 <= lon <= 90. Latitude is positive north and negative south.

Definition at line 267 of file FGLocation.h.

267 { ComputeDerived(); return radtodeg*mLat; }

◆ GetLongitude()

double GetLongitude ( void  ) const
inline

Get the longitude.

Returns
the longitude in rad of the location represented with this class instance. The returned values are in the range between -pi <= lon <= pi. Longitude is positive east and negative west.

Definition at line 234 of file FGLocation.h.

234 { ComputeDerived(); return mLon; }
+ Here is the caller graph for this function:

◆ GetLongitudeDeg()

double GetLongitudeDeg ( void  ) const
inline

Get the longitude.

Returns
the longitude in deg of the location represented with this class instance. The returned values are in the range between -180 <= lon <= 180. Longitude is positive east and negative west.

Definition at line 240 of file FGLocation.h.

240 { ComputeDerived(); return radtodeg*mLon; }

◆ GetRadius()

double GetRadius ( void  ) const
inline

Get the distance from the center of the earth in feet.

Returns
the distance of the location represented with this class instance to the center of the earth in ft. The radius value is always positive.

Definition at line 291 of file FGLocation.h.

291 { ComputeDerived(); return mRadius; }
+ Here is the caller graph for this function:

◆ GetTec2l()

const FGMatrix33& GetTec2l ( void  ) const
inline

Transform matrix from the earth centered to local horizontal frame.

Returns
a const reference to the rotation matrix of the transform from the earth centered frame to the local horizontal frame.

Definition at line 301 of file FGLocation.h.

301 { ComputeDerived(); return mTec2l; }

◆ GetTl2ec()

const FGMatrix33& GetTl2ec ( void  ) const
inline

Transform matrix from local horizontal to earth centered frame.

Returns
a const reference to the rotation matrix of the transform from the local horizontal frame to the earth centered frame.

Definition at line 296 of file FGLocation.h.

296 { ComputeDerived(); return mTl2ec; }

◆ LocalToLocation()

FGLocation LocalToLocation ( const FGColumnVector3 lvec) const
inline

Conversion from Local frame coordinates to a location in the earth centered and fixed frame.

This function calculates the FGLocation of an object which position relative to the vehicle is given as in input.

Parameters
lvecVector in the local horizontal coordinate frame
Returns
The location in the earth centered and fixed frame

Definition at line 326 of file FGLocation.h.

326  {
327  ComputeDerived(); return mTl2ec*lvec + mECLoc;
328  }
+ Here is the caller graph for this function:

◆ LocationToLocal()

FGColumnVector3 LocationToLocal ( const FGColumnVector3 ecvec) const
inline

Conversion from a location in the earth centered and fixed frame to local horizontal frame coordinates.

This function calculates the relative position between the vehicle and the input vector and returns the result expressed in the local frame.

Parameters
ecvecVector in the earth centered and fixed frame
Returns
The vector in the local horizontal coordinate frame

Definition at line 336 of file FGLocation.h.

336  {
337  ComputeDerived(); return mTec2l*(ecvec - mECLoc);
338  }

◆ operator()() [1/2]

double& operator() ( unsigned int  idx)
inline

Write access the entries of the vector.

Parameters
idxthe component index.
Returns
a reference to the vector entry at the given index. Indices are counted starting with 1. Note that the index given in the argument is unchecked.

Definition at line 354 of file FGLocation.h.

354 { mCacheValid = false; return mECLoc.Entry(idx); }

◆ operator()() [2/2]

double operator() ( unsigned int  idx) const
inline

Read access the entries of the vector.

Parameters
idxthe component index. Return the value of the matrix entry at the given index. Indices are counted starting with 1. Note that the index given in the argument is unchecked.

Definition at line 347 of file FGLocation.h.

347 { return mECLoc.Entry(idx); }

◆ operator*()

FGLocation operator* ( double  scalar) const
inline

This operator scales an ECEF position vector.

A new object is returned that defines a position made of the cartesian coordinates of the provided ECEF position scaled by the supplied scalar value.

Definition at line 469 of file FGLocation.h.

469  {
470  FGLocation result(scalar*mECLoc);
471  if (mEllipseSet) result.SetEllipse(a, ec*a);
472  return result;
473  }
FGLocation(void)
Default constructor.
Definition: FGLocation.cpp:56
+ Here is the call graph for this function:

◆ operator*=()

const FGLocation& operator*= ( double  scalar)
inline

This operator scales the ECEF position vector.

The cartesian coordinates of the ECEF position vector on the left side of the equality are scaled by the supplied value (right side), and a reference to this object is returned.

Definition at line 433 of file FGLocation.h.

433  {
434  mCacheValid = false;
435  mECLoc *= scalar;
436  return *this;
437  }

◆ operator+()

FGLocation operator+ ( const FGLocation l) const
inline

This operator adds two ECEF position vectors.

A new object is returned that defines a position which is the sum of the cartesian coordinates of the two positions provided.

Definition at line 450 of file FGLocation.h.

450  {
451  FGLocation result(mECLoc + l.mECLoc);
452  if (mEllipseSet) result.SetEllipse(a, ec*a);
453  return result;
454  }
+ Here is the call graph for this function:

◆ operator+=()

const FGLocation& operator+= ( const FGLocation l)
inline

This operator adds the ECEF position vectors.

The cartesian coordinates of the supplied vector (right side) are added to the ECEF position vector on the left side of the equality, and a reference to this object is returned.

Definition at line 413 of file FGLocation.h.

413  {
414  mCacheValid = false;
415  mECLoc += l.mECLoc;
416  return *this;
417  }

◆ operator-()

FGLocation operator- ( const FGLocation l) const
inline

This operator substracts two ECEF position vectors.

A new object is returned that defines a position which is the difference of the cartesian coordinates of the two positions provided.

Definition at line 459 of file FGLocation.h.

459  {
460  FGLocation result(mECLoc - l.mECLoc);
461  if (mEllipseSet) result.SetEllipse(a, ec*a);
462  return result;
463  }
+ Here is the call graph for this function:

◆ operator-=()

const FGLocation& operator-= ( const FGLocation l)
inline

This operator substracts the ECEF position vectors.

The cartesian coordinates of the supplied vector (right side) are substracted from the ECEF position vector on the left side of the equality, and a reference to this object is returned.

Definition at line 423 of file FGLocation.h.

423  {
424  mCacheValid = false;
425  mECLoc -= l.mECLoc;
426  return *this;
427  }

◆ operator/=()

const FGLocation& operator/= ( double  scalar)
inline

This operator scales the ECEF position vector.

The cartesian coordinates of the ECEF position vector on the left side of the equality are scaled by the inverse of the supplied value (right side), and a reference to this object is returned.

Definition at line 443 of file FGLocation.h.

443  {
444  return operator*=(1.0/scalar);
445  }
const FGLocation & operator*=(double scalar)
This operator scales the ECEF position vector.
Definition: FGLocation.h:433

◆ operator=() [1/2]

const FGLocation& operator= ( const FGColumnVector3 v)
inline

Sets this location via the supplied vector.

The location can be set by an Earth-centered, Earth-fixed (ECEF) frame position vector. The cache is marked as invalid, so any future requests for selected important data will cause the parameters to be calculated.

Parameters
vthe ECEF column vector in feet.
Returns
a reference to the FGLocation object.

Definition at line 384 of file FGLocation.h.

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  }

◆ operator=() [2/2]

FGLocation & operator= ( const FGLocation l)

Sets this location via the supplied location object.

Parameters
lA location object reference.
Returns
a reference to the FGLocation object.

Definition at line 140 of file FGLocation.cpp.

141 {
142  mECLoc = l.mECLoc;
143  mCacheValid = l.mCacheValid;
144  mEllipseSet = l.mEllipseSet;
145 
146  a = l.a;
147  e2 = l.e2;
148  c = l.c;
149  ec = l.ec;
150  ec2 = l.ec2;
151 
152  //ag See comment in constructor above
153  if (!mCacheValid) return *this;
154 
155  mLon = l.mLon;
156  mLat = l.mLat;
157  mRadius = l.mRadius;
158 
159  mTl2ec = l.mTl2ec;
160  mTec2l = l.mTec2l;
161 
162  mGeodLat = l.mGeodLat;
163  GeodeticAltitude = l.GeodeticAltitude;
164 
165  return *this;
166 }

◆ SetEllipse()

void SetEllipse ( double  semimajor,
double  semiminor 
)

Sets the semimajor and semiminor axis lengths for this planet.

The eccentricity and flattening are calculated from the semimajor and semiminor axis lengths.

Parameters
semimajorplanet semi-major axis in ft.
semiminorplanet semi-minor axis in ft.

Definition at line 259 of file FGLocation.cpp.

260 {
261  mCacheValid = false;
262  mEllipseSet = true;
263 
264  a = semimajor;
265  ec = semiminor/a;
266  ec2 = ec * ec;
267  e2 = 1.0 - ec2;
268  c = a * e2;
269 }
+ Here is the caller graph for this function:

◆ SetLatitude()

void SetLatitude ( double  latitude)

Set the GEOCENTRIC latitude.

Parameters
latitudeGEOCENTRIC latitude in rad to set. Sets the latitude of the location represented with this class instance to the value of the given argument. The value is meant to be in rad. The longitude and the radius value are preserved with this call with the exception of radius being equal to zero. If the radius is previously set to zero it is changed to be equal to 1.0 past this call. Latitude is positive north and negative south. The arguments should be within the bounds of -pi/2 <= lat <= pi/2. The behavior of this function with arguments outside this range is left as an exercise to the gentle reader ...

Definition at line 190 of file FGLocation.cpp.

191 {
192  mCacheValid = false;
193 
194  double r = mECLoc.Magnitude();
195  if (r == 0.0) {
196  mECLoc(eX) = 1.0;
197  r = 1.0;
198  }
199 
200  double rtmp = mECLoc.Magnitude(eX, eY);
201  if (rtmp != 0.0) {
202  double fac = r/rtmp*cos(latitude);
203  mECLoc(eX) *= fac;
204  mECLoc(eY) *= fac;
205  } else {
206  mECLoc(eX) = r*cos(latitude);
207  mECLoc(eY) = 0.0;
208  }
209  mECLoc(eZ) = r*sin(latitude);
210 }
double Magnitude(void) const
Length of the vector.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetLongitude()

void SetLongitude ( double  longitude)

Set the longitude.

Parameters
longitudeLongitude in rad to set. Sets the longitude of the location represented with this class instance to the value of the given argument. The value is meant to be in rad. The latitude and the radius value are preserved with this call with the exception of radius being equal to zero. If the radius is previously set to zero it is changed to be equal to 1.0 past this call. Longitude is positive east and negative west. The arguments should be within the bounds of -pi <= lon <= pi. The behavior of this function with arguments outside this range is left as an exercise to the gentle reader ...

Definition at line 170 of file FGLocation.cpp.

171 {
172  double rtmp = mECLoc.Magnitude(eX, eY);
173  // Check if we have zero radius.
174  // If so set it to 1, so that we can set a position
175  if (0.0 == mECLoc.Magnitude())
176  rtmp = 1.0;
177 
178  // Fast return if we are on the north or south pole ...
179  if (rtmp == 0.0)
180  return;
181 
182  mCacheValid = false;
183 
184  mECLoc(eX) = rtmp*cos(longitude);
185  mECLoc(eY) = rtmp*sin(longitude);
186 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetPosition()

void SetPosition ( double  lon,
double  lat,
double  radius 
)

Sets the longitude, latitude and the distance from the center of the earth.

Parameters
lonlongitude in radians
latGEOCENTRIC latitude in radians
radiusdistance from center of earth to vehicle in feet

Definition at line 227 of file FGLocation.cpp.

228 {
229  mCacheValid = false;
230 
231  double sinLat = sin(lat);
232  double cosLat = cos(lat);
233  double sinLon = sin(lon);
234  double cosLon = cos(lon);
235 
236  mECLoc = { radius*cosLat*cosLon,
237  radius*cosLat*sinLon,
238  radius*sinLat };
239 }

◆ SetPositionGeodetic()

void SetPositionGeodetic ( double  lon,
double  lat,
double  height 
)

Sets the longitude, latitude and the distance above the reference spheroid.

Parameters
lonlongitude in radians
latGEODETIC latitude in radians
heightdistance above the reference ellipsoid to vehicle in feet

Definition at line 243 of file FGLocation.cpp.

244 {
245  assert(mEllipseSet);
246  mCacheValid = false;
247 
248  double slat = sin(lat);
249  double clat = cos(lat);
250  double RN = a / sqrt(1.0 - e2*slat*slat);
251 
252  mECLoc(eX) = (RN + height)*clat*cos(lon);
253  mECLoc(eY) = (RN + height)*clat*sin(lon);
254  mECLoc(eZ) = ((1 - e2)*RN + height)*slat;
255 }
+ Here is the caller graph for this function:

◆ SetRadius()

void SetRadius ( double  radius)

Set the distance from the center of the earth.

Parameters
radiusRadius in ft to set. Sets the radius of the location represented with this class instance to the value of the given argument. The value is meant to be in ft. The latitude and longitude values are preserved with this call with the exception of radius being equal to zero. If the radius is previously set to zero, latitude and longitude is set equal to zero past this call. The argument should be positive. The behavior of this function called with a negative argument is left as an exercise to the gentle reader ...

Definition at line 214 of file FGLocation.cpp.

215 {
216  mCacheValid = false;
217 
218  double rold = mECLoc.Magnitude();
219  if (rold == 0.0)
220  mECLoc(eX) = radius;
221  else
222  mECLoc *= radius/rold;
223 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: