diff -r f774ff724ee4 src/mobility/position-allocator.cc --- a/src/mobility/position-allocator.cc Mon Sep 07 11:59:10 2009 +0100 +++ b/src/mobility/position-allocator.cc Tue Sep 08 09:58:07 2009 +0200 @@ -315,4 +315,72 @@ } + +NS_OBJECT_ENSURE_REGISTERED (UniformDiscPositionAllocator); + +TypeId +UniformDiscPositionAllocator::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::UniformDiscPositionAllocator") + .SetParent () + .SetGroupName ("Mobility") + .AddConstructor () + .AddAttribute ("rho", + "The radius of the disc", + DoubleValue (0.0), + MakeDoubleAccessor (&UniformDiscPositionAllocator::m_rho), + MakeDoubleChecker ()) + .AddAttribute ("X", + "The x coordinate of the center of the disc.", + DoubleValue (0.0), + MakeDoubleAccessor (&UniformDiscPositionAllocator::m_x), + MakeDoubleChecker ()) + .AddAttribute ("Y", + "The y coordinate of the center of the disc.", + DoubleValue (0.0), + MakeDoubleAccessor (&UniformDiscPositionAllocator::m_y), + MakeDoubleChecker ()) + ; + return tid; +} + +UniformDiscPositionAllocator::UniformDiscPositionAllocator () +{} +UniformDiscPositionAllocator::~UniformDiscPositionAllocator () +{} + +void +UniformDiscPositionAllocator::SetRho (double rho) +{ + m_rho = rho; +} +void +UniformDiscPositionAllocator::SetX (double x) +{ + m_x = x; +} +void +UniformDiscPositionAllocator::SetY (double y) +{ + m_y = y; +} +Vector +UniformDiscPositionAllocator::GetNext (void) const +{ + UniformVariable r (-m_rho, m_rho); + double x,y; + do + { + x = r.GetValue (); + y = r.GetValue (); + } + while (sqrt(x*x + y*y) > m_rho); + + x += m_x; + y += m_y; + NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y); + return Vector (x, y, 0.0); +} + + } // namespace ns3 diff -r f774ff724ee4 src/mobility/position-allocator.h --- a/src/mobility/position-allocator.h Mon Sep 07 11:59:10 2009 +0100 +++ b/src/mobility/position-allocator.h Tue Sep 08 09:58:07 2009 +0200 @@ -182,7 +182,8 @@ /** * \brief allocate random positions within a disc - * according to a pair of random variables. + * according to a given distribution for the polar coordinates of each + * node with respect to the provided center of the disc */ class RandomDiscPositionAllocator : public PositionAllocator { @@ -204,6 +205,30 @@ double m_y; }; + +/** + * \brief allocate positions which are uniformly distributed within a + * disc of a given radius. Note that this is NOT equivalent to using + * a RandomDiscPositionAllocator with a uniformly-distributed rho. + */ +class UniformDiscPositionAllocator : public PositionAllocator +{ +public: + static TypeId GetTypeId (void); + UniformDiscPositionAllocator (); + virtual ~UniformDiscPositionAllocator (); + + void SetRho (double rho); + void SetX (double x); + void SetY (double y); + + virtual Vector GetNext (void) const; +private: + double m_rho; + double m_x; + double m_y; +}; + } // namespace ns3 #endif /* RANDOM_POSITION_H */