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