145 lines
5.7 KiB
C++
145 lines
5.7 KiB
C++
#ifndef GERMANAIRLINESVA_FILE_FSUIPC_FSLATLONPOINTIMPL_H
|
|
#define GERMANAIRLINESVA_FILE_FSUIPC_FSLATLONPOINTIMPL_H
|
|
|
|
#include "FsLatLonPoint.h"
|
|
|
|
namespace germanairlinesva
|
|
{
|
|
namespace file
|
|
{
|
|
namespace FSUIPC
|
|
{
|
|
inline FsLatLonPoint::FsLatLonPoint() = default;
|
|
inline FsLatLonPoint::FsLatLonPoint(FsLatitude Latitude,
|
|
FsLongitude Longitude)
|
|
{
|
|
this->lon = Longitude;
|
|
this->lat = Latitude;
|
|
}
|
|
|
|
inline const FsLongitude FsLatLonPoint::Longitude() const
|
|
{
|
|
return this->lon;
|
|
}
|
|
inline const FsLatitude FsLatLonPoint::Latitude() const
|
|
{
|
|
return this->lat;
|
|
}
|
|
|
|
inline double
|
|
FsLatLonPoint::DistanceFromInFeet(const FsLatLonPoint &Point) const
|
|
{
|
|
FsLongitudeSpan fsLongitudeSpan =
|
|
FsLongitudeSpan::BetweenTwoLongitudes(Point.Longitude(), this->lon);
|
|
double num = (fsLongitudeSpan.ToFeet(this->lat) +
|
|
fsLongitudeSpan.ToFeet(Point.lat)) /
|
|
2.0;
|
|
double feet = FsLatitudeSpan(Point.Latitude().DecimalDegrees() -
|
|
this->lat.DecimalDegrees())
|
|
.ToFeet();
|
|
return sqrt(num * num + feet * feet);
|
|
}
|
|
inline double FsLatLonPoint::DistanceFromInNauticalMiles(
|
|
const FsLatLonPoint &Point) const
|
|
{
|
|
return this->DistanceFromInFeet(Point) / 6076.1155;
|
|
}
|
|
inline double
|
|
FsLatLonPoint::DistanceFromInMetres(const FsLatLonPoint &Point) const
|
|
{
|
|
return this->DistanceFromInFeet(Point) / 3.2808;
|
|
}
|
|
|
|
inline double FsLatLonPoint::BearingTo(const FsLatLonPoint &Point) const
|
|
{
|
|
double num1 = 0.0;
|
|
double num2 = abs(FsLatitudeSpan(this->lat.DecimalDegrees() -
|
|
Point.Latitude().DecimalDegrees())
|
|
.ToFeet());
|
|
double num3 = abs((FsLongitudeSpan(Point.Longitude().DecimalDegrees() -
|
|
this->lon.DecimalDegrees())
|
|
.ToFeet(this->lat) +
|
|
FsLongitudeSpan(Point.Longitude().DecimalDegrees() -
|
|
this->lon.DecimalDegrees())
|
|
.ToFeet(Point.lat)) /
|
|
2.0);
|
|
if (num2 == 0.0)
|
|
num1 = this->lon.DecimalDegrees() > Point.Longitude().DecimalDegrees()
|
|
? 270.0
|
|
: 90.0;
|
|
else if (this->lat.DecimalDegrees() < Point.Latitude().DecimalDegrees() &&
|
|
this->lon.DecimalDegrees() < Point.Longitude().DecimalDegrees())
|
|
num1 = atan(num3 / num2) * 180.0 / M_PI;
|
|
else if (this->lat.DecimalDegrees() > Point.Latitude().DecimalDegrees() &&
|
|
this->lon.DecimalDegrees() < Point.Longitude().DecimalDegrees())
|
|
num1 = atan(num2 / num3) * 180.0 / M_PI + 90.0;
|
|
else if (this->lat.DecimalDegrees() > Point.Latitude().DecimalDegrees() &&
|
|
this->lon.DecimalDegrees() > Point.Longitude().DecimalDegrees())
|
|
num1 = atan(num3 / num2) * 180.0 / M_PI + 180.0;
|
|
else if (this->lat.DecimalDegrees() < Point.Latitude().DecimalDegrees() &&
|
|
this->lon.DecimalDegrees() > Point.Longitude().DecimalDegrees())
|
|
num1 = atan(num2 / num3) * 180.0 / M_PI + 270.0;
|
|
return num1;
|
|
}
|
|
inline double FsLatLonPoint::BearingFrom(const FsLatLonPoint &Point) const
|
|
{
|
|
double num = 180.0 + this->BearingTo(Point);
|
|
if (num >= 360.0)
|
|
num -= 360.0;
|
|
if (num < 0.0)
|
|
num += 360.0;
|
|
return num;
|
|
}
|
|
|
|
inline FsLatLonPoint FsLatLonPoint::OffsetByFeet(double Bearing,
|
|
double Distance) const
|
|
{
|
|
double Feet1 = sin(M_PI * Bearing / 180.0) * Distance;
|
|
double Feet2 = cos(M_PI * Bearing / 180.0) * Distance;
|
|
FsLatLonPoint fsLatLonPoint = FsLatLonPoint();
|
|
fsLatLonPoint.lat = this->lat.Add(FsLatitudeSpan::FromFeet(Feet2));
|
|
fsLatLonPoint.lon =
|
|
this->lon.Add(FsLongitudeSpan::FromFeet(Feet1, fsLatLonPoint.lat));
|
|
return fsLatLonPoint;
|
|
}
|
|
inline FsLatLonPoint FsLatLonPoint::OffsetByMetres(double Bearing,
|
|
double Distance) const
|
|
{
|
|
double Metres1 = sin(M_PI * Bearing / 180.0) * Distance;
|
|
double Metres2 = cos(M_PI * Bearing / 180.0) * Distance;
|
|
FsLatLonPoint fsLatLonPoint = FsLatLonPoint();
|
|
fsLatLonPoint.lat = this->lat.Add(FsLatitudeSpan::FromMetres(Metres2));
|
|
fsLatLonPoint.lon = this->lon.Add(
|
|
FsLongitudeSpan::FromMetres(Metres1, fsLatLonPoint.lat));
|
|
return fsLatLonPoint;
|
|
}
|
|
inline FsLatLonPoint
|
|
FsLatLonPoint::OffsetByNauticalMiles(double Bearing,
|
|
double Distance) const
|
|
{
|
|
double NauticalMiles1 = sin(M_PI * Bearing / 180.0) * Distance;
|
|
double NauticalMiles2 = cos(M_PI * Bearing / 180.0) * Distance;
|
|
FsLatLonPoint fsLatLonPoint = FsLatLonPoint();
|
|
fsLatLonPoint.lat =
|
|
this->lat.Add(FsLatitudeSpan::FromNauticalMiles(NauticalMiles2));
|
|
fsLatLonPoint.lon =
|
|
this->lon.Add(FsLongitudeSpan::FromNauticalMiles(NauticalMiles1,
|
|
fsLatLonPoint.lat));
|
|
return fsLatLonPoint;
|
|
}
|
|
|
|
inline const std::string FsLatLonPoint::to_string(bool HemisphereAsText,
|
|
char DetailLevel) const
|
|
{
|
|
return this->lat.to_string(HemisphereAsText, DetailLevel) + ", " +
|
|
this->lon.to_string(HemisphereAsText, DetailLevel);
|
|
}
|
|
inline const std::string FsLatLonPoint::to_string() const
|
|
{
|
|
return this->to_string(true, 'm');
|
|
}
|
|
} // namespace FSUIPC
|
|
} // namespace file
|
|
} // namespace germanairlinesva
|
|
|
|
#endif |