A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
geographic-positions.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Benjamin Cizdziel <ben.cizdziel@gmail.com>
7 */
8
9#include "ns3/random-variable-stream.h"
10#include "ns3/vector.h"
11
12#ifndef GEOGRAPHIC_POSITIONS_H
13#define GEOGRAPHIC_POSITIONS_H
14
15namespace ns3
16{
17
18/**
19 * @ingroup mobility
20 *
21 * Consists of methods dealing with Earth geographic coordinates and locations.
22 */
24{
25 public:
26 /**
27 * Spheroid model to use for earth: perfect sphere (SPHERE), Geodetic
28 * Reference System 1980 (GRS80), or World Geodetic System 1984 (WGS84)
29 *
30 * Moritz, H. "Geodetic Reference System 1980." GEODETIC REFERENCE SYSTEM 1980.
31 * <https://web.archive.org/web/20170712034716/http://www.gfy.ku.dk/~iag/HB2000/part4/grs80_corr.htm>.
32 *
33 * "Department of Defense World Geodetic System 1984." National Imagery and
34 * Mapping Agency, 1 Jan. 2000.
35 * <https://web.archive.org/web/20200729203634/https://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf>.
36 */
37
38 /// geocentric gravitational constant is 398600.7 KM^3/s^2
39 /// https://ntrs.nasa.gov/citations/19760058274 or 3.986007×10^14 m^3/s^2
40 static constexpr double LEO_EARTH_GGC = 3.986007e14;
41
42 /// Earth's radius in meters if modeled as a perfect sphere
43 static constexpr double EARTH_SPHERE_RADIUS = 6371e3;
44
45 /// Earth's eccentricity if modeled as a perfect sphere
46 static constexpr double EARTH_SPHERE_ECCENTRICITY = 0;
47
48 /// Earth's flattening if modeled as a perfect sphere
49 static constexpr double EARTH_SPHERE_FLATTENING = 0;
50
51 /// <Earth's semi-major axis in meters as defined by both GRS80 and WGS84
52 /// https://en.wikipedia.org/wiki/World_Geodetic_System
53 static constexpr double EARTH_SEMIMAJOR_AXIS = 6378137;
54
55 /// Earth's first eccentricity as defined by GRS80
56 /// https://en.wikipedia.org/wiki/Geodetic_Reference_System_1980
57 static constexpr double EARTH_GRS80_ECCENTRICITY = 0.0818191910428158;
58
59 /// Earth's first flattening as defined by GRS80
60 /// https://en.wikipedia.org/wiki/Geodetic_Reference_System_1980
61 static constexpr double EARTH_GRS80_FLATTENING = 0.003352810681183637418;
62
63 /// Earth's first eccentricity as defined by
64 /// https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84
65 static constexpr double EARTH_WGS84_ECCENTRICITY = 0.0818191908426215;
66
67 /// Earth's first flattening as defined by WGS84
68 /// https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84
69 static constexpr double EARTH_WGS84_FLATTENING = 0.00335281;
70
71 /// The possible Earth spheroid models. .
78
79 /**
80 * Converts earth geographic/geodetic coordinates (latitude and longitude in
81 * degrees) with a given altitude above earth's surface (in meters) to Earth
82 * Centered Earth Fixed (ECEF) Cartesian coordinates (x, y, z in meters),
83 * where origin (0, 0, 0) is the center of the earth.
84 *
85 * @param latitude earth-referenced latitude (in degrees) of the point
86 * @param longitude earth-referenced longitude (in degrees) of the point
87 * @param altitude height of the point (in meters) above earth's surface
88 * @param sphType earth spheroid model to use for conversion
89 *
90 * @return a vector representing the Cartesian coordinates (x, y, z referenced
91 * in meters) of the point (origin (0, 0, 0) is center of earth)
92 */
93 static Vector GeographicToCartesianCoordinates(double latitude,
94 double longitude,
95 double altitude,
96 EarthSpheroidType sphType);
97
98 /**
99 * Inverse of GeographicToCartesianCoordinates using [1]
100 *
101 * This function iteratively converts cartesian (ECEF) coordinates to
102 * geographic coordinates. The residual delta is 1 m, which is approximately
103 * 1 / 30 arc seconds or 9.26e-6 deg.
104 *
105 * @param pos a vector representing the Cartesian coordinates (x, y, z referenced
106 * in meters) of the point (origin (0, 0, 0) is center of earth)
107 * @param sphType earth spheroid model to use for conversion
108 *
109 * @return Vector position where x = latitude (deg), y = longitude (deg),
110 * z = altitude above the ellipsoid (m)
111 *
112 * [1] "Ellipsoidal and Cartesian Coordinates Conversion", Navipedia,
113 * European Space Agency, Jul 8, 2019.
114 * <https://gssc.esa.int/navipedia/index.php/Ellipsoidal_and_Cartesian_Coordinates_Conversion>
115 */
116 static Vector CartesianToGeographicCoordinates(Vector pos, EarthSpheroidType sphType);
117
118 /**
119 * Conversion from geographic to topocentric coordinates.
120 *
121 * Conversion formulas taken from [1, Sec. 4.1.3 "Geographic/topocentric conversions"].
122 * [1] IOGP. Geomatics guidance note 7, part 2: coordinate conversions & transformations
123 * including formulas. IOGP Publication 373-7-2, International Association For Oil And Gas
124 * Producers, Sep. 2019
125 * https://www.iogp.org/bookstore/product/coordinate-conversions-and-transformation-including-formulas/
126 *
127 * @param pos a vector representing the Geographic coordinates (latitude, longitude, altitude)
128 * in degrees (lat/lon) and meters (altitude).
129 * @param refPoint a vector representing the reference point (latitude, longitude, altitude) in
130 * degrees (lat/lon) and meters (altitude). Default is (0,0,0)
131 * @param sphType earth spheroid model to use for conversion
132 *
133 * @return Vector position in meters and using planar Cartesian coordinates, i.e., ns-3's
134 * defaults
135 */
136 static Vector GeographicToTopocentricCoordinates(Vector pos,
137 Vector refPoint,
138 EarthSpheroidType sphType);
139
140 /**
141 * Conversion from topocentric to geographic.
142 *
143 * Conversion formulas taken from [1, Sec. 4.1.3 "Geographic/topocentric conversions"].
144 * [1] IOGP. Geomatics guidance note 7, part 2: coordinate conversions & transformations
145 * including formulas. IOGP Publication 373-7-2, International Association For Oil And Gas
146 * Producers, Sep. 2019
147 * https://www.iogp.org/bookstore/product/coordinate-conversions-and-transformation-including-formulas/
148 *
149 * @param pos a vector representing the topocentric coordinates (u, v, w) in meters, which
150 * represent the cartesian coordinates along the xEast, yNorth and zUp axes, respectively..
151 * @param refPoint a vector representing the reference point (latitude, longitude, altitude) in
152 * degrees (lat/lon) and meters (altitude). Default is (0,0,0)
153 * @param sphType earth spheroid model to use for conversion
154 *
155 * @return Vector position (latitude, longitude, altitude) in degrees (lat/lon) and meters
156 * (altitude) converted to geographic coordinates
157 */
158 static Vector TopocentricToGeographicCoordinates(Vector pos,
159 Vector refPoint,
160 EarthSpheroidType sphType);
161
162 /**
163 * Generates uniformly distributed random points (in ECEF Cartesian
164 * coordinates) within a given altitude above earth's surface centered around
165 * a given origin point (on earth's surface, in geographic/geodetic coordinates)
166 * within a given distance radius (using arc length of earth's surface, not
167 * pythagorean distance).
168 * Distance radius is measured as if all generated points are on earth's
169 * surface (with altitude = 0).
170 * Assumes earth is a perfect sphere.
171 *
172 * @param originLatitude origin point latitude in degrees
173 * @param originLongitude origin point longitude in degrees
174 * @param maxAltitude maximum altitude in meters above earth's surface with
175 * which random points can be generated
176 * @param numPoints number of points to generate
177 * @param maxDistFromOrigin max distance in meters from origin with which
178 * random transmitters can be generated (all transmitters are less than or
179 * equal to this distance from the origin, relative to points being on earth's
180 * surface)
181 * @param uniRand pointer to the uniform random variable to use for random
182 * location and altitude generation
183 *
184 * @return a list containing the vectors (x, y, z location referenced in
185 * meters from origin at center of earth) of each point generated
186 */
187 static std::list<Vector> RandCartesianPointsAroundGeographicPoint(
188 double originLatitude,
189 double originLongitude,
190 double maxAltitude,
191 int numPoints,
192 double maxDistFromOrigin,
194
195 /**
196 * @param type the type of model which is used to model the Earth
197 *
198 * @return the corresponding radius (in meters), first eccentricity and first flattening values
199 */
200 static std::tuple<double, double, double> GetRadiusEccentFlat(EarthSpheroidType type);
201};
202
203} // namespace ns3
204
205#endif /* GEOGRAPHIC_POSITIONS_H */
Consists of methods dealing with Earth geographic coordinates and locations.
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...
static constexpr double EARTH_SPHERE_FLATTENING
Earth's flattening if modeled as a perfect sphere.
static constexpr double EARTH_SPHERE_ECCENTRICITY
Earth's eccentricity if modeled as a perfect sphere.
static constexpr double EARTH_SPHERE_RADIUS
Earth's radius in meters if modeled as a perfect sphere.
EarthSpheroidType
The possible Earth spheroid models. .
static constexpr double EARTH_GRS80_FLATTENING
Earth's first flattening as defined by GRS80 https://en.wikipedia.org/wiki/Geodetic_Reference_System_...
static constexpr double EARTH_WGS84_ECCENTRICITY
Earth's first eccentricity as defined by https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84.
static Vector TopocentricToGeographicCoordinates(Vector pos, Vector refPoint, EarthSpheroidType sphType)
Conversion from topocentric to geographic.
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 constexpr double EARTH_WGS84_FLATTENING
Earth's first flattening as defined by WGS84 https://en.wikipedia.org/wiki/World_Geodetic_System#WGS8...
static constexpr double LEO_EARTH_GGC
Spheroid model to use for earth: perfect sphere (SPHERE), Geodetic Reference System 1980 (GRS80),...
static Vector GeographicToTopocentricCoordinates(Vector pos, Vector refPoint, EarthSpheroidType sphType)
Conversion from geographic to topocentric coordinates.
static Vector CartesianToGeographicCoordinates(Vector pos, EarthSpheroidType sphType)
Inverse of GeographicToCartesianCoordinates using [1].
static constexpr double EARTH_SEMIMAJOR_AXIS
<Earth's semi-major axis in meters as defined by both GRS80 and WGS84 https://en.wikipedia....
static std::tuple< double, double, double > GetRadiusEccentFlat(EarthSpheroidType type)
static constexpr double EARTH_GRS80_ECCENTRICITY
Earth's first eccentricity as defined by GRS80 https://en.wikipedia.org/wiki/Geodetic_Reference_Syste...
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Every class exported by the ns3 library is enclosed in the ns3 namespace.