Skip to content

Instantly share code, notes, and snippets.

@Gabrielcarvfer
Last active December 17, 2021 14:42
Show Gist options
  • Save Gabrielcarvfer/e188e558ca4bf93093814f4ac6f05db0 to your computer and use it in GitHub Desktop.
Save Gabrielcarvfer/e188e558ca4bf93093814f4ac6f05db0 to your computer and use it in GitHub Desktop.
#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