View | Details | Raw Unified | Return to bug 672
Collapse All | Expand All

(-)a/src/mobility/position-allocator.cc (+68 lines)
 Lines 315-318    Link Here 
315
}
315
}
316
316
317
317
318
319
NS_OBJECT_ENSURE_REGISTERED (UniformDiscPositionAllocator);
320
321
TypeId
322
UniformDiscPositionAllocator::GetTypeId (void)
323
{
324
  static TypeId tid = TypeId ("ns3::UniformDiscPositionAllocator")
325
    .SetParent<PositionAllocator> ()
326
    .SetGroupName ("Mobility")
327
    .AddConstructor<UniformDiscPositionAllocator> ()
328
    .AddAttribute ("rho",
329
                   "The radius of the disc",
330
                   DoubleValue (0.0),
331
                   MakeDoubleAccessor (&UniformDiscPositionAllocator::m_rho),
332
                   MakeDoubleChecker<double> ())
333
    .AddAttribute ("X",
334
                   "The x coordinate of the center of the  disc.",
335
                   DoubleValue (0.0),
336
                   MakeDoubleAccessor (&UniformDiscPositionAllocator::m_x),
337
                   MakeDoubleChecker<double> ())
338
    .AddAttribute ("Y",
339
                   "The y coordinate of the center of the  disc.",
340
                   DoubleValue (0.0),
341
                   MakeDoubleAccessor (&UniformDiscPositionAllocator::m_y),
342
                   MakeDoubleChecker<double> ())
343
    ;
344
  return tid;
345
}   
346
347
UniformDiscPositionAllocator::UniformDiscPositionAllocator ()
348
{}
349
UniformDiscPositionAllocator::~UniformDiscPositionAllocator ()
350
{}
351
352
void 
353
UniformDiscPositionAllocator::SetRho (double rho)
354
{
355
  m_rho = rho;
356
}
357
void 
358
UniformDiscPositionAllocator::SetX (double x)
359
{
360
  m_x = x;
361
}
362
void 
363
UniformDiscPositionAllocator::SetY (double y)
364
{
365
  m_y = y;
366
}
367
Vector
368
UniformDiscPositionAllocator::GetNext (void) const
369
{
370
  UniformVariable r (-m_rho, m_rho);
371
  double x,y;
372
  do
373
    {
374
      x = r.GetValue ();
375
      y = r.GetValue ();
376
    }
377
  while (sqrt(x*x + y*y) > m_rho);
378
  
379
  x += m_x;
380
  y += m_y;
381
  NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y);
382
  return Vector (x, y, 0.0);
383
}
384
385
318
} // namespace ns3 
386
} // namespace ns3 
(-)a/src/mobility/position-allocator.h (-1 / +26 lines)
 Lines 182-188    Link Here 
182
182
183
/**
183
/**
184
 * \brief allocate random positions within a disc
184
 * \brief allocate random positions within a disc
185
 * according to a pair of random variables.
185
 * according to a given distribution for the polar coordinates of each
186
 * node with respect to the provided center of the disc 
186
 */
187
 */
187
class RandomDiscPositionAllocator : public PositionAllocator
188
class RandomDiscPositionAllocator : public PositionAllocator
188
{
189
{
 Lines 204-209    Link Here 
204
  double m_y;
205
  double m_y;
205
};
206
};
206
207
208
209
/**
210
 * \brief allocate positions which are uniformly distributed within a
211
 * disc of a given radius.  Note that this is NOT equivalent to using
212
 * a RandomDiscPositionAllocator with a uniformly-distributed rho.
213
 */
214
class UniformDiscPositionAllocator : public PositionAllocator
215
{
216
public:
217
  static TypeId GetTypeId (void);
218
  UniformDiscPositionAllocator ();
219
  virtual ~UniformDiscPositionAllocator ();
220
221
  void SetRho (double rho);
222
  void SetX (double x);
223
  void SetY (double y);
224
225
  virtual Vector GetNext (void) const;
226
private:
227
  double m_rho;
228
  double m_x;
229
  double m_y;
230
};
231
207
} // namespace ns3
232
} // namespace ns3
208
233
209
#endif /* RANDOM_POSITION_H */
234
#endif /* RANDOM_POSITION_H */

Return to bug 672