A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rand-cart-around-geo-test.cc
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/geographic-positions.h>
21#include <ns3/log.h>
22#include <ns3/test.h>
23
24#include <cmath>
25
26/**
27 * This test verifies the accuracy of the RandCartesianPointsAroundGeographicPoint()
28 * method in the GeographicPositions class, which generates uniformly
29 * distributed random points (in ECEF Cartesian coordinates) within a given
30 * altitude above earth's surface centered around a given origin point (on
31 * earth's surface, in geographic/geodetic coordinates) within a given distance
32 * radius (using arc length of earth's surface, not pythagorean distance).
33 * Distance radius is measured as if all generated points are on earth's
34 * surface (with altitude = 0). Assumes earth is a perfect sphere. To verify the
35 * method, this test checks that the generated points are within the given
36 * maximum distance radius from the origin. Since this is testing the distance
37 * radius from the origin, all points generated in this test are on earth's
38 * surface (altitude = 0), since the distance radius has been defined as if all
39 * points are on earth's surface. The pythagorean (straight-line) distance
40 * between each generated point and the origin is first calculated, and then
41 * using this distance and the radius of the earth, the distance radius to the
42 * origin (arc length) is calculated. This distance radius is compared to the
43 * max distance radius to ensure that it is less than the maximum.
44 */
45NS_LOG_COMPONENT_DEFINE("RandCartAroundGeoTest");
46
47using namespace ns3;
48
49/**
50 * 0.1 meter tolerance for testing, which is very small compared to the maximum
51 * distances from origin being tested
52 */
53const double TOLERANCE = 0.1;
54
55/// earth's radius in meters if modeled as a perfect sphere
56static const double EARTH_RADIUS = 6371e3;
57
58/**
59 * \ingroup mobility-test
60 *
61 * \brief Rand Cart Around Geo Test Case
62 */
64{
65 public:
66 /**
67 * Constructor
68 *
69 * \param originLatitude origin latitude
70 * \param originLongitude origin longitude
71 * \param maxAltitude maximum altitude
72 * \param numPoints number of points
73 * \param maxDistFromOrigin maximum distance from origin
74 * \param uniRand random variable
75 */
76 RandCartAroundGeoTestCase(double originLatitude,
77 double originLongitude,
78 double maxAltitude,
79 int numPoints,
80 double maxDistFromOrigin,
83
84 private:
85 void DoRun() override;
86 /**
87 * name function
88 * \param originLatitude the origin latitude
89 * \param originLongitude the origin longitude
90 * \param maxDistFromOrigin the maximum distance from the origin
91 * \returns the name string
92 */
93 static std::string Name(double originLatitude,
94 double originLongitude,
95 double maxDistFromOrigin);
96 double m_originLatitude; ///< origin latitude
97 double m_originLongitude; ///< origin longitude
98 double m_maxAltitude; ///< maximum altitude
99 int m_numPoints; ///< number of points
100 double m_maxDistFromOrigin; ///< maximum distance from origin
102};
103
104std::string
106 double originLongitude,
107 double maxDistFromOrigin)
108{
109 std::ostringstream oss;
110 oss << "origin latitude = " << originLatitude << " degrees, "
111 << "origin longitude = " << originLongitude << " degrees, "
112 << "max distance from origin = " << maxDistFromOrigin;
113 return oss.str();
114}
115
117 double originLongitude,
118 double maxAltitude,
119 int numPoints,
120 double maxDistFromOrigin,
122 : TestCase(Name(originLatitude, originLongitude, maxDistFromOrigin)),
123 m_originLatitude(originLatitude),
124 m_originLongitude(originLongitude),
125 m_maxAltitude(maxAltitude),
126 m_numPoints(numPoints),
127 m_maxDistFromOrigin(maxDistFromOrigin),
128 m_uniRand(uniRand)
129{
130}
131
133{
134}
135
136void
138{
139 std::list<Vector> points =
145 m_uniRand);
146 Vector origin =
151 Vector randPoint;
152 while (!points.empty())
153 {
154 randPoint = points.front();
155 points.pop_front();
156
157 // pythagorean distance between random point and origin, not distance on surface of earth
158 double straightDistFromOrigin =
159 sqrt(pow(randPoint.x - origin.x, 2) + pow(randPoint.y - origin.y, 2) +
160 pow(randPoint.z - origin.z, 2));
161
162 // arc length distance between random point and origin, on surface of earth
163 double arcDistFromOrigin =
164 2 * EARTH_RADIUS * asin(straightDistFromOrigin / (2 * EARTH_RADIUS));
165
166 NS_TEST_ASSERT_MSG_LT(arcDistFromOrigin,
168 "random point (" << randPoint.x << ", " << randPoint.y << ", "
169 << randPoint.z
170 << ") is outside of max radius from origin");
171 }
172}
173
174/**
175 * \ingroup mobility-test
176 *
177 * \brief Rand Cart Around Geo Test Suite
178 */
180{
181 public:
183};
184
186 : TestSuite("rand-cart-around-geo", Type::UNIT)
187{
188 NS_LOG_INFO("creating RandCartAroundGeoTestSuite");
189 Ptr<UniformRandomVariable> uniRand = CreateObject<UniformRandomVariable>();
190 uniRand->SetStream(5);
191 for (double originLatitude = -89.9; originLatitude <= 89.9; originLatitude += 35.96)
192 {
193 for (double originLongitude = 0; originLongitude <= 360; originLongitude += 72)
194 {
195 for (double maxDistFromOrigin = 1000; maxDistFromOrigin <= 1000000;
196 maxDistFromOrigin *= 10)
197 {
198 AddTestCase(new RandCartAroundGeoTestCase(originLatitude,
199 originLongitude,
200 0, // on earth's surface
201 50, // 50 points generated
202 maxDistFromOrigin,
203 uniRand),
204 TestCase::Duration::QUICK);
205 }
206 }
207 }
208}
209
210/**
211 * \ingroup mobility-test
212 * Static variable for test initialization
213 */
Rand Cart Around Geo Test Case.
double m_maxAltitude
maximum altitude
void DoRun() override
Implementation to actually run this TestCase.
double m_originLongitude
origin longitude
double m_originLatitude
origin latitude
static std::string Name(double originLatitude, double originLongitude, double maxDistFromOrigin)
name function
RandCartAroundGeoTestCase(double originLatitude, double originLongitude, double maxAltitude, int numPoints, double maxDistFromOrigin, Ptr< UniformRandomVariable > uniRand)
Constructor.
double m_maxDistFromOrigin
maximum distance from origin
Ptr< UniformRandomVariable > m_uniRand
random number
Rand Cart Around Geo Test Suite.
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 Vector GeographicToCartesianCoordinates(double latitude, double longitude, double altitude, EarthSpheroidType sphType)
Converts earth geographic/geodetic coordinates (latitude and longitude in degrees) with a given altit...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
static RandCartAroundGeoTestSuite g_RandCartAroundGeoTestSuite
Static variable for test initialization.
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Definition: test.h:710
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const double EARTH_RADIUS
earth's radius in meters if modeled as a perfect sphere
const double TOLERANCE
0.1 meter tolerance for testing, which is very small compared to the maximum distances from origin be...
static std::string Name(std::string str, uint32_t totalStreamSize, uint32_t sourceWriteSize, uint32_t serverReadSize, uint32_t serverWriteSize, uint32_t sourceReadSize, bool useIpv6)
Definition: tcp-test.cc:166