mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 18:13:57 +02:00
Add lat long conversion
This commit is contained in:
parent
b7f459e36a
commit
70c70a19ce
8 changed files with 171 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
#include "ns3/object-factory.h"
|
||||
#include "ns3/node-container.h"
|
||||
#include "ns3/constant-position-mobility-model.h"
|
||||
#include "ns3/leo-lat-long.h"
|
||||
|
||||
#define LEO_GND_RAD_EARTH 6.371e6
|
||||
|
||||
/**
|
||||
* \brief Builds a node container of nodes with constant positions
|
||||
|
@ -31,6 +34,15 @@ public:
|
|||
*/
|
||||
NodeContainer Install (const std::string &wpFile);
|
||||
|
||||
/**
|
||||
*
|
||||
* \param location1 first location
|
||||
* \param location2 second location
|
||||
* \returns a node container containing nodes using the specified attributes
|
||||
*/
|
||||
NodeContainer Install (const LeoLatLong &location1,
|
||||
const LeoLatLong &location2);
|
||||
|
||||
/**
|
||||
* Set an attribute for each node
|
||||
*
|
||||
|
@ -41,6 +53,8 @@ public:
|
|||
|
||||
private:
|
||||
ObjectFactory m_gndNodeFactory;
|
||||
|
||||
static Vector3D GetEarthPosition (const LeoLatLong &loc);
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue