53 static constexpr
double DEG2RAD = M_PI / 180.0;
56 static constexpr
double RAD2DEG = 180.0 * M_1_PI;
65 double latitudeRadians =
DEG2RAD * latitude;
66 double longitudeRadians =
DEG2RAD * longitude;
74 else if (sphType ==
GRS80)
85 double Rn = a / (sqrt (1 - pow (e, 2) * pow (sin (latitudeRadians), 2)));
87 double x = (Rn + altitude) * cos (latitudeRadians) * cos (longitudeRadians);
88 double y = (Rn + altitude) * cos (latitudeRadians) * sin (longitudeRadians);
89 double z = ((1 - pow (e, 2)) * Rn + altitude) * sin (latitudeRadians);
90 Vector cartesianCoordinates = Vector (
x, y, z);
91 return cartesianCoordinates;
106 else if (sphType ==
GRS80)
118 lla.y = atan2 (pos.y, pos.x);
123 lla.x = atan2 (pos.z, p * (1 - e2));
128 double N = a / sqrt (1 - e2 * sin (tmp.x) * sin (tmp.x));
129 double v = p / cos (tmp.x);
131 lla.x = atan2 (pos.z, p * (1 - e2 * N / v));
134 while (fabs (lla.x - tmp.x) > 0.00000926 *
DEG2RAD);
143 lla.y += lla.y < 0 ? 180 : -180;
145 else if (lla.x < -90.0)
147 lla.x = -180 - lla.x;
148 lla.y += lla.y < 0 ? 180 : -180;
150 if (lla.y == 180.0) lla.y = -180;
154 NS_ASSERT_MSG (-180.0 <= lla.y,
"Conversion error: longitude too negative");
155 NS_ASSERT_MSG (180.0 > lla.y,
"Conversion error: longitude too positive");
156 NS_ASSERT_MSG (-90.0 <= lla.x,
"Conversion error: latitude too negative");
157 NS_ASSERT_MSG (90.0 >= lla.x,
"Conversion error: latitude too positive");
164 double originLongitude,
167 double maxDistFromOrigin,
172 if (originLatitude >= 90)
174 NS_LOG_WARN (
"origin latitude must be less than 90. setting to 89.999");
175 originLatitude = 89.999;
177 else if (originLatitude <= -90)
179 NS_LOG_WARN (
"origin latitude must be greater than -90. setting to -89.999");
180 originLatitude = -89.999;
187 NS_LOG_WARN (
"maximum altitude must be greater than or equal to 0. setting to 0");
191 double originLatitudeRadians = originLatitude *
DEG2RAD;
192 double originLongitudeRadians = originLongitude *
DEG2RAD;
193 double originColatitude = (M_PI_2) - originLatitudeRadians;
203 std::list<Vector> generatedPoints;
204 for (
int i = 0; i < numPoints; i++)
209 double phi = uniRand->
GetValue (0, M_PI * 2);
215 double theta = M_PI_2 -
alpha;
218 double randPointLatitude = asin(sin(theta)*cos(originColatitude) +
219 cos(theta)*sin(originColatitude)*sin(phi));
221 double intermedLong = asin((sin(randPointLatitude)*cos(originColatitude) -
222 sin(theta)) / (cos(randPointLatitude)*sin(originColatitude)));
224 intermedLong = intermedLong + M_PI_2;
228 if (phi > (M_PI_2) && phi <= (3 * M_PI_2))
229 intermedLong = -intermedLong;
232 double randPointLongitude = intermedLong + originLongitudeRadians;
235 double randAltitude = uniRand->
GetValue (0, maxAltitude);
245 generatedPoints.push_back (pointPosition);
248 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.
float alpha
Plot alpha value (transparency)
list x
Random number samples.