25 #include <ns3/fatal-error.h>
31 NS_LOG_COMPONENT_DEFINE(
"geo-coordinate");
42 bool correctIfInvalid)
43 : m_refEllipsoid(refEllipsoid)
45 NS_LOG_FUNCTION(
this << latitude << longitude << altitude);
47 Construct(latitude, longitude, altitude, correctIfInvalid);
53 bool correctIfInvalid)
56 NS_LOG_FUNCTION(
this << latitude << longitude << altitude);
58 Construct(latitude, longitude, altitude, correctIfInvalid);
64 NS_LOG_FUNCTION(
this << vector);
70 : m_refEllipsoid(refEllipsoid)
72 NS_LOG_FUNCTION(
this << vector);
83 NS_LOG_FUNCTION(
this);
91 NS_LOG_FUNCTION(
this << latitude << longitude << altitude);
97 latitude = 180 - latitude;
102 latitude = -180 - latitude;
106 while (longitude > 180)
110 while (longitude < -180)
118 NS_FATAL_ERROR(
"Invalid latitude!!! Got " << latitude);
123 NS_FATAL_ERROR(
"Invalid longitude!!! Got " << longitude);
128 NS_FATAL_ERROR(
"Invalid altitude!!! Got " << altitude);
141 NS_LOG_FUNCTION(
this);
159 NS_LOG_FUNCTION(
this);
176 NS_FATAL_ERROR(
"Invalid Reference Ellipsoid!!!");
188 NS_LOG_FUNCTION(
this);
195 NS_LOG_FUNCTION(
this);
202 NS_LOG_FUNCTION(
this);
209 NS_LOG_FUNCTION(
this << longitude);
213 NS_FATAL_ERROR(
"Invalid longitude!!!");
222 NS_LOG_FUNCTION(
this << latitude);
226 NS_FATAL_ERROR(
"Invalid latitude!!!");
235 NS_LOG_FUNCTION(
this << altitude);
239 NS_FATAL_ERROR(
"Invalid altitude!!!");
248 NS_LOG_FUNCTION(
this << v);
253 double op = std::sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
258 double lon = std::atan(v.y / v.x);
261 if (v.x != 0 || v.y != 0)
281 double latG = std::atan(v.z / (std::sqrt(v.x * v.x + v.y * v.y)));
285 double latQ = std::atan(v.z / ((1 -
m_e2Param) * (std::sqrt(v.x * v.x + v.y * v.y))));
291 double xQ = rCurvature * std::cos(latQ) * std::cos(lon);
292 double yQ = rCurvature * std::cos(latQ) * std::sin(lon);
293 double zQ = rCurvature * (1 -
m_e2Param) * std::sin(latQ);
296 double oq = std::sqrt(xQ * xQ + yQ * yQ + zQ * zQ);
303 double tp = pq * std::sin(latG - latQ);
320 double polarRadius = NAN;
322 switch (refEllipsoid)
337 NS_FATAL_ERROR(
"Invalid polar radius value!!!");
341 return ((polarRadius + altitude) >= 0);
351 os << latitude <<
"," << longitude <<
"," << altitude;
365 is >> latitude >> c1 >> longitude >> c2 >> altitude;
371 if (c1 !=
',' || c2 !=
',')
373 is.setstate(std::ios_base::failbit);
GeoCoordinate class is used to store and operate with geodetic coordinates.
static constexpr double polarRadius_grs80
void SetAltitude(double altitude)
Sets altitude value of coordinate.
ReferenceEllipsoid_t m_refEllipsoid
void SetLatitude(double latitude)
Sets latitude value of coordinate.
static constexpr double polarRadius_wgs84
static bool IsValidAltitude(double altitude, ReferenceEllipsoid_t refEllipsoide)
Checks if altitude is in valid range.
double m_altitude
altitude of coordinate
double GetAltitude() const
Gets altitude value of coordinate.
void SetLongitude(double longitude)
Sets longitude value of coordinate.
double GetLatitude() const
Gets latitude value of coordinate.
void Initialize()
This method is called to initialize needed parameters according to used reference ellipsoide.
GeoCoordinate()
Create GeoCoordinate with zero values of longitude, latitude and altitude.
static bool IsValidLongitude(double longitude)
Checks if longitude is in valid range.
double GetLongitude() const
Gets longitude value of coordinate.
static bool IsValidLatitude(double latitude)
Checks if latitude is in valid range.
Vector ToVector() const
Converts Geodetic coordinates to Cartesian coordinates.
void ConstructFromVector(const Vector &vector)
Creates Geodetic coordinates from given Cartesian coordinates.
double m_latitude
latitude of coordinate
double GetRadiusCurvature(double latitude) const
Gets the radius of curvature in the prime vertical.
static constexpr double equatorRadius
double m_longitude
longitude of coordinate
void Construct(double latitude, double longitude, double altitude, bool correctIfInvalid)
static constexpr double polarRadius_sphere
static T RadiansToDegrees(T radian)
Converts radians to degrees.
static T DegreesToRadians(T degree)
Converts degrees to radians.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
std::istream & operator>>(std::istream &is, GeoCoordinate &coordinate)
std::ostream & operator<<(std::ostream &os, const GeoCoordinate &coordinate)
ATTRIBUTE_HELPER_CPP(GeoCoordinate)