25 #include <ns3/fatal-error.h>
35 NS_LOG_COMPONENT_DEFINE(
"geo-coordinate");
46 bool correctIfInvalid)
47 : m_refEllipsoid(refEllipsoid)
49 NS_LOG_FUNCTION(
this << latitude << longitude << altitude);
51 Construct(latitude, longitude, altitude, correctIfInvalid);
57 bool correctIfInvalid)
60 NS_LOG_FUNCTION(
this << latitude << longitude << altitude);
62 Construct(latitude, longitude, altitude, correctIfInvalid);
68 NS_LOG_FUNCTION(
this << vector);
74 : m_refEllipsoid(refEllipsoid)
76 NS_LOG_FUNCTION(
this << vector);
87 NS_LOG_FUNCTION(
this);
95 NS_LOG_FUNCTION(
this << latitude << longitude << altitude);
101 latitude = 180 - latitude;
106 latitude = -180 - latitude;
110 while (longitude > 180)
114 while (longitude < -180)
122 NS_FATAL_ERROR(
"Invalid latitude!!! Got " << latitude);
127 NS_FATAL_ERROR(
"Invalid longitude!!! Got " << longitude);
132 NS_FATAL_ERROR(
"Invalid altitude!!! Got " << altitude);
145 NS_LOG_FUNCTION(
this);
163 NS_LOG_FUNCTION(
this);
180 NS_FATAL_ERROR(
"Invalid Reference Ellipsoid!!!");
192 NS_LOG_FUNCTION(
this);
199 NS_LOG_FUNCTION(
this);
206 NS_LOG_FUNCTION(
this);
213 NS_LOG_FUNCTION(
this << longitude);
217 NS_FATAL_ERROR(
"Invalid longitude!!!");
226 NS_LOG_FUNCTION(
this << latitude);
230 NS_FATAL_ERROR(
"Invalid latitude!!!");
239 NS_LOG_FUNCTION(
this << altitude);
243 NS_FATAL_ERROR(
"Invalid altitude!!!");
252 NS_LOG_FUNCTION(
this << v);
257 double op = std::sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
262 double lon = std::atan(v.y / v.x);
265 if (v.x != 0 || v.y != 0)
285 double latG = std::atan(v.z / (std::sqrt(v.x * v.x + v.y * v.y)));
289 double latQ = std::atan(v.z / ((1 -
m_e2Param) * (std::sqrt(v.x * v.x + v.y * v.y))));
295 double xQ = rCurvature * std::cos(latQ) * std::cos(lon);
296 double yQ = rCurvature * std::cos(latQ) * std::sin(lon);
297 double zQ = rCurvature * (1 -
m_e2Param) * std::sin(latQ);
300 double oq = std::sqrt(xQ * xQ + yQ * yQ + zQ * zQ);
307 double tp = pq * std::sin(latG - latQ);
324 double polarRadius = NAN;
326 switch (refEllipsoid)
341 NS_FATAL_ERROR(
"Invalid polar radius value!!!");
345 return ((polarRadius + altitude) >= 0);
355 os << latitude <<
"," << longitude <<
"," << altitude;
369 is >> latitude >> c1 >> longitude >> c2 >> altitude;
375 if (c1 !=
',' || c2 !=
',')
377 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)