Add lat long conversion

This commit is contained in:
Tim Schubert 2020-08-23 21:25:54 +02:00
parent b7f459e36a
commit 70c70a19ce
8 changed files with 171 additions and 16 deletions

View file

@ -1,5 +1,7 @@
#include <fstream>
#include "math.h"
#include "ns3/log.h"
#include "ns3/config.h"
#include "ns3/waypoint.h"
@ -52,4 +54,39 @@ LeoGndNodeHelper::Install (const std::string &wpFile)
return nodes;
}
Vector3D
LeoGndNodeHelper::GetEarthPosition (const LeoLatLong &loc)
{
double lat = loc.latitude * (M_PI / 90);
double lon = loc.longitude * (M_PI / 180);
Vector3D pos = Vector3D (LEO_GND_RAD_EARTH * sin (lat) * cos (lon),
LEO_GND_RAD_EARTH * sin (lat) * sin (lon),
LEO_GND_RAD_EARTH * cos (lat));
return pos;
}
NodeContainer
LeoGndNodeHelper::Install (const LeoLatLong &location1,
const LeoLatLong &location2)
{
NS_LOG_FUNCTION (this << location1 << location2);
NodeContainer nodes;
for (const LeoLatLong loc : { location1, location2 })
{
Vector pos = GetEarthPosition (loc);
Ptr<ConstantPositionMobilityModel> mob = CreateObject<ConstantPositionMobilityModel> ();
mob->SetPosition (pos);
Ptr<Node> node = m_gndNodeFactory.Create<Node> ();
node->AggregateObject (mob);
nodes.Add (node);
NS_LOG_INFO ("Added ground node at " << pos);
}
NS_LOG_INFO ("Added " << nodes.GetN () << " ground nodes");
return nodes;
}
}; // namespace ns3