55 static constexpr
double DEG2RAD = M_PI / 180.0;
58 static constexpr
double RAD2DEG = 180.0 * M_1_PI;
67 double latitudeRadians =
DEG2RAD * latitude;
68 double longitudeRadians =
DEG2RAD * longitude;
76 else if (sphType ==
GRS80)
87 double Rn = a / (sqrt(1 - pow(e, 2) * pow(sin(latitudeRadians), 2)));
89 double x = (Rn + altitude) * cos(latitudeRadians) * cos(longitudeRadians);
90 double y = (Rn + altitude) * cos(latitudeRadians) * sin(longitudeRadians);
91 double z = ((1 - pow(e, 2)) * Rn + altitude) * sin(latitudeRadians);
92 Vector cartesianCoordinates = Vector(
x, y, z);
93 return cartesianCoordinates;
108 else if (sphType ==
GRS80)
121 lla.y = atan2(pos.y, pos.x);
126 lla.x = atan2(pos.z, p * (1 - e2));
131 double N = a / sqrt(1 - e2 * sin(tmp.x) * sin(tmp.x));
132 double v = p / cos(tmp.x);
134 lla.x = atan2(pos.z, p * (1 - e2 * N / v));
137 while (fabs(lla.x - tmp.x) > 0.00000926 *
DEG2RAD);
146 lla.y += lla.y < 0 ? 180 : -180;
148 else if (lla.x < -90.0)
150 lla.x = -180 - lla.x;
151 lla.y += lla.y < 0 ? 180 : -180;
160 NS_ASSERT_MSG(-180.0 <= lla.y,
"Conversion error: longitude too negative");
161 NS_ASSERT_MSG(180.0 > lla.y,
"Conversion error: longitude too positive");
162 NS_ASSERT_MSG(-90.0 <= lla.x,
"Conversion error: latitude too negative");
163 NS_ASSERT_MSG(90.0 >= lla.x,
"Conversion error: latitude too positive");
170 double originLongitude,
173 double maxDistFromOrigin,
178 if (originLatitude >= 90)
180 NS_LOG_WARN(
"origin latitude must be less than 90. setting to 89.999");
181 originLatitude = 89.999;
183 else if (originLatitude <= -90)
185 NS_LOG_WARN(
"origin latitude must be greater than -90. setting to -89.999");
186 originLatitude = -89.999;
193 NS_LOG_WARN(
"maximum altitude must be greater than or equal to 0. setting to 0");
197 double originLatitudeRadians = originLatitude *
DEG2RAD;
198 double originLongitudeRadians = originLongitude *
DEG2RAD;
199 double originColatitude = (M_PI_2)-originLatitudeRadians;
209 std::list<Vector> generatedPoints;
210 for (
int i = 0; i < numPoints; i++)
215 double phi = uniRand->
GetValue(0, M_PI * 2);
221 double theta = M_PI_2 - alpha;
224 double randPointLatitude = asin(sin(theta) * cos(originColatitude) +
225 cos(theta) * sin(originColatitude) * sin(phi));
227 double intermedLong = asin((sin(randPointLatitude) * cos(originColatitude) - sin(theta)) /
228 (cos(randPointLatitude) * sin(originColatitude)));
230 intermedLong = intermedLong + M_PI_2;
234 if (phi > (M_PI_2) && phi <= (3 * M_PI_2))
236 intermedLong = -intermedLong;
240 double randPointLongitude = intermedLong + originLongitudeRadians;
243 double randAltitude = uniRand->
GetValue(0, maxAltitude);
245 Vector pointPosition =
253 generatedPoints.push_back(pointPosition);
256 return generatedPoints;
static std::list< Vector > RandCartesianPointsAroundGeographicPoint(double originLatitude, double originLongitude, double maxAltitude, int numPoints, double maxDistFromOrigin, Ptr< UniformRandomVariable > uniRand)
Generates uniformly distributed random points (in ECEF Cartesian coordinates) within a given altitude...
EarthSpheroidType
Spheroid model to use for earth: perfect sphere (SPHERE), Geodetic Reference System 1980 (GRS80),...
static Vector GeographicToCartesianCoordinates(double latitude, double longitude, double altitude, EarthSpheroidType sphType)
Converts earth geographic/geodetic coordinates (latitude and longitude in degrees) with a given altit...
static Vector CartesianToGeographicCoordinates(Vector pos, EarthSpheroidType sphType)
Inverse of GeographicToCartesianCoordinates using [1].
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static constexpr double DEG2RAD
Conversion factor: degrees to radians.
static constexpr double EARTH_GRS80_ECCENTRICITY
Earth's first eccentricity as defined by GRS80.
static constexpr double EARTH_RADIUS
Earth's radius in meters if modeled as a perfect sphere.
static constexpr double EARTH_SEMIMAJOR_AXIS
GRS80 and WGS84 sources.
static constexpr double RAD2DEG
Conversion factor: radians to degrees.
double CalculateDistance(const Vector3D &a, const Vector3D &b)
static constexpr double EARTH_WGS84_ECCENTRICITY
Earth's first eccentricity as defined by WGS84.