46 #include "FGLocation.h" 50 IDENT(IdSrc,
"$Id: FGLocation.cpp,v 1.34 2015/09/20 20:53:13 bcoconni Exp $");
51 IDENT(IdHdr,ID_LOCATION);
54 FGGroundCallback_ptr FGLocation::GroundCallback = NULL;
61 : mECLoc(1.0, 0.0, 0.0), mCacheValid(false)
67 mLon = mLat = mRadius = 0.0;
68 mGeodLat = GeodeticAltitude = 0.0;
87 mLon = mLat = mRadius = 0.0;
88 mGeodLat = GeodeticAltitude = 0.0;
97 double sinLat = sin(lat);
98 double cosLat = cos(lat);
99 double sinLon = sin(lon);
100 double cosLon = cos(lon);
102 radius*cosLat*sinLon,
109 : mECLoc(lv), mCacheValid(false)
115 mLon = mLat = mRadius = 0.0;
116 mGeodLat = GeodeticAltitude = 0.0;
129 : mECLoc(l.mECLoc), mCacheValid(l.mCacheValid)
144 if (!mCacheValid)
return;
157 mGeodLat = l.mGeodLat;
158 GeodeticAltitude = l.GeodeticAltitude;
166 mCacheValid = l.mCacheValid;
176 if (!mCacheValid)
return *
this;
189 mGeodLat = l.mGeodLat;
190 GeodeticAltitude = l.GeodeticAltitude;
211 mECLoc(eX) = rtmp*cos(longitude);
212 mECLoc(eY) = rtmp*sin(longitude);
229 double fac = r/rtmp*cos(latitude);
233 mECLoc(eX) = r*cos(latitude);
236 mECLoc(eZ) = r*sin(latitude);
249 mECLoc *= radius/rold;
258 double sinLat = sin(lat);
259 double cosLat = cos(lat);
260 double sinLon = sin(lon);
261 double cosLon = cos(lon);
264 radius*cosLat*sinLon,
274 double slat = sin(lat);
275 double clat = cos(lat);
276 double RN = a / sqrt(1.0 - e2*slat*slat);
278 mECLoc(eX) = (RN + height)*clat*cos(lon);
279 mECLoc(eY) = (RN + height)*clat*sin(lon);
280 mECLoc(eZ) = ((1 - e2)*RN + height)*slat;
298 void FGLocation::ComputeDerivedUnconditional(
void)
const 305 double r02 = mECLoc(eX)*mECLoc(eX) + mECLoc(eY)*mECLoc(eY);
306 double rxy = sqrt(r02);
309 double sinLon, cosLon;
314 sinLon = mECLoc(eY)/rxy;
315 cosLon = mECLoc(eX)/rxy;
319 double sinLat, cosLat;
320 if (mRadius == 0.0) {
324 sinLat = mECLoc(eZ)/mRadius;
325 cosLat = rxy/mRadius;
329 if ( mECLoc( eX ) == 0.0 && mECLoc( eY ) == 0.0 )
332 mLon = atan2( mECLoc( eY ), mECLoc( eX ) );
334 if ( rxy == 0.0 && mECLoc( eZ ) == 0.0 )
337 mLat = atan2( mECLoc(eZ), rxy );
345 mTec2l =
FGMatrix33( -cosLon*sinLat, -sinLon*sinLat, cosLat,
346 -sinLon , cosLon , 0.0 ,
347 -cosLon*cosLat, -sinLon*cosLat, -sinLat );
356 double cos_epa = cos(epa);
357 double sin_epa = sin(epa);
359 -sin_epa, cos_epa, 0.0,
365 mTl2i = mTec2i * mTl2ec;
377 double s0 = fabs(mECLoc(eZ));
379 double c0 = ec * rxy;
380 double c02 = c0 * c0;
381 double s02 = s0 * s0;
382 double a02 = c02 + s02;
383 double a0 = sqrt(a02);
384 double a03 = a02 * a0;
385 double s1 = zc*a03 + c*s02*s0;
386 double c1 = rxy*a03 - c*c02*c0;
387 double cs0c0 = c*c0*s0;
388 double b0 = 1.5*cs0c0*((rxy*s0-zc*c0)*a0-cs0c0);
390 double cc = ec*(c1*a03-b0*c0);
391 mGeodLat = sign(mECLoc(eZ))*atan(s1 / cc);
392 double s12 = s1 * s1;
393 double cc2 = cc * cc;
394 GeodeticAltitude = (rxy*cc + s0*s1 - a*sqrt(ec2*s12 + cc2)) / sqrt(s12 + cc2);
419 double target_latitude)
const 421 double delta_lat_rad = target_latitude -
GetLatitude();
422 double delta_lon_rad = target_longitude -
GetLongitude();
424 double distance_a = pow(sin(0.5*delta_lat_rad), 2.0)
426 * (pow(sin(0.5*delta_lon_rad), 2.0)));
428 return 2.0 *
GetRadius() * atan2(sqrt(distance_a), sqrt(1.0 - distance_a));
448 double target_latitude)
const 450 double delta_lon_rad = target_longitude -
GetLongitude();
452 double Y = sin(delta_lon_rad) * cos(target_latitude);
456 double heading_to_waypoint_rad = atan2(Y, X);
457 if (heading_to_waypoint_rad < 0) heading_to_waypoint_rad += 2.0*M_PI;
459 return heading_to_waypoint_rad;
void SetPosition(double lon, double lat, double radius)
Sets the longitude, latitude and the distance from the center of the earth.
void SetLongitude(double longitude)
Set the longitude.
void SetLatitude(double latitude)
Set the latitude.
void SetRadius(double radius)
Set the distance from the center of the earth.
double GetSinLatitude() const
Get the sine of Latitude.
double GetDistanceTo(double target_longitude, double target_latitude) const
Get the geodetic distance between the current location and a given location.
double GetLatitude() const
Get the latitude.
FGLocation holds an arbitrary location in the Earth centered Earth fixed reference frame (ECEF)...
void SetPositionGeodetic(double lon, double lat, double height)
Sets the longitude, latitude and the distance above the reference ellipsoid.
double GetRadius() const
Get the distance from the center of the earth.
void SetEllipse(double semimajor, double semiminor)
Sets the semimajor and semiminor axis lengths for this planet.
const FGLocation & operator=(const FGColumnVector3 &v)
Sets this location via the supplied vector.
double GetLongitude() const
Get the longitude.
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...
FGLocation(void)
Default constructor.
This class implements a 3 element column vector.
double GetCosLatitude() const
Get the cosine of Latitude.
Handles matrix math operations.
FGMatrix33 Transposed(void) const
Transposed matrix.
double Magnitude(void) const
Length of the vector.
void InitMatrix(void)
Initialize the matrix.