Last active
December 17, 2021 14:42
-
-
Save Gabrielcarvfer/e188e558ca4bf93093814f4ac6f05db0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <ns3/core-module.h> | |
#include <ns3/mobility-module.h> | |
#include <ns3/netanim-module.h> | |
using namespace ns3; | |
Vector polarToRectangular(double radius, double theta, double offsetx, double offsety) | |
{ | |
double y = radius*sin(theta); | |
double x = radius*cos(theta); | |
return Vector(offsetx+x, offsety+y, 0); | |
} | |
int main() | |
{ | |
double placementRadius = 100.0; //meters | |
unsigned numNodes = 10; | |
NodeContainer nodes; | |
nodes.Create(numNodes); | |
Ptr <ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>(); | |
double angleBetweenNodes = 2*M_PI/numNodes; | |
for (unsigned i = 0; i < numNodes; i++) { | |
positionAlloc->Add(polarToRectangular(placementRadius, angleBetweenNodes*i, placementRadius, placementRadius)); | |
} | |
MobilityHelper mobility; | |
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); | |
mobility.SetPositionAllocator(positionAlloc); | |
mobility.Install(nodes); | |
AnimationInterface anim("anim.xml"); | |
Simulator::Stop(Seconds(1.0)); | |
Simulator::Run(); | |
Simulator::Destroy(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment