src/mobility/random-position.cc
changeset 2503 e667dc0f350e
parent 2357 d64b1561b1c2
parent 2502 50d0da37f02f
child 2504 da3ec9cc3ba3
equal deleted inserted replaced
2357:d64b1561b1c2 2503:e667dc0f350e
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2007 INRIA
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License version 2 as
       
     7  * published by the Free Software Foundation;
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    17  *
       
    18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
       
    19  */
       
    20 #include "random-position.h"
       
    21 #include "ns3/random-variable.h"
       
    22 #include "ns3/default-value.h"
       
    23 #include "ns3/random-variable-default-value.h"
       
    24 #include "ns3/log.h"
       
    25 #include <cmath>
       
    26 
       
    27 NS_LOG_COMPONENT_DEFINE ("RandomPosition");
       
    28 
       
    29 namespace ns3 {
       
    30 
       
    31 static RandomVariableDefaultValue
       
    32 g_rectangleX ("RandomRectanglePositionX",
       
    33 	      "A random variable which represents the x position of a position in a random rectangle.",
       
    34 	      "Uniform:0:200");
       
    35 
       
    36 static RandomVariableDefaultValue
       
    37 g_rectangleY ("RandomRectanglePositionY",
       
    38 	      "A random variable which represents the y position of a position in a random rectangle.",
       
    39 	      "Uniform:0:200");
       
    40 
       
    41 static RandomVariableDefaultValue
       
    42 g_discTheta ("RandomDiscPositionTheta",
       
    43 	     "A random variable which represents the angle (gradients) of a position in a random disc.",
       
    44 	     "Uniform:0:6.2830");
       
    45 
       
    46 static RandomVariableDefaultValue
       
    47 g_discRho ("RandomDiscPositionRho",
       
    48 	   "A random variable which represents the radius of a position in a random disc.",
       
    49 	   "Uniform:0:200");
       
    50 
       
    51 static NumericDefaultValue<double>
       
    52 g_discX ("RandomDiscPositionX",
       
    53 	 "The x coordinate of the center of the random position disc.",
       
    54 	 0.0);
       
    55 
       
    56 static NumericDefaultValue<double>
       
    57 g_discY ("RandomDiscPositionY",
       
    58 	 "The y coordinate of the center of the random position disc.",
       
    59 	 0.0);
       
    60 
       
    61 NS_OBJECT_ENSURE_REGISTERED (RandomPosition);
       
    62 
       
    63 TypeId 
       
    64 RandomPosition::GetTypeId (void)
       
    65 {
       
    66   static TypeId tid = TypeId ("RandomPosition")
       
    67     .SetParent<Object> ();
       
    68   return tid;
       
    69 }
       
    70 
       
    71 RandomPosition::RandomPosition ()
       
    72 {
       
    73 }
       
    74 
       
    75 RandomPosition::~RandomPosition ()
       
    76 {}
       
    77 
       
    78 NS_OBJECT_ENSURE_REGISTERED (RandomRectanglePosition);
       
    79 
       
    80 TypeId
       
    81 RandomRectanglePosition::GetTypeId (void)
       
    82 {
       
    83   static TypeId tid = TypeId ("RandomRectanglePosition")
       
    84     .SetParent<RandomPosition> ()
       
    85     .AddConstructor<RandomRectanglePosition> ()
       
    86     .AddConstructor<RandomRectanglePosition, const RandomVariable &, const RandomVariable &> ();
       
    87   return tid;
       
    88 }
       
    89 
       
    90 RandomRectanglePosition::RandomRectanglePosition ()
       
    91   : m_x (g_rectangleX.Get ()),
       
    92     m_y (g_rectangleY.Get ())
       
    93 {}
       
    94 RandomRectanglePosition::RandomRectanglePosition (const RandomVariable &x,
       
    95 						  const RandomVariable &y)
       
    96   : m_x (x),
       
    97     m_y (y)
       
    98 {}
       
    99 RandomRectanglePosition::~RandomRectanglePosition ()
       
   100 {}
       
   101 Vector
       
   102 RandomRectanglePosition::Get (void) const
       
   103 {
       
   104   double x = m_x.GetValue ();
       
   105   double y = m_y.GetValue ();
       
   106   return Vector (x, y, 0.0);
       
   107 }
       
   108 
       
   109 NS_OBJECT_ENSURE_REGISTERED (RandomDiscPosition);
       
   110 
       
   111 TypeId
       
   112 RandomDiscPosition::GetTypeId (void)
       
   113 {
       
   114   static TypeId tid = TypeId ("RandomDiscPosition")
       
   115     .SetParent<RandomPosition> ()
       
   116     .AddConstructor<RandomDiscPosition> ()
       
   117     .AddConstructor<RandomDiscPosition, const RandomVariable &, const RandomVariable &, double, double> ();
       
   118   return tid;
       
   119 }   
       
   120 
       
   121 RandomDiscPosition::RandomDiscPosition ()
       
   122   : m_theta (g_discTheta.Get ()),
       
   123     m_rho (g_discRho.Get ()),
       
   124     m_x (g_discX.GetValue ()),
       
   125     m_y (g_discY.GetValue ())
       
   126 {}
       
   127 RandomDiscPosition::RandomDiscPosition (const RandomVariable &theta,
       
   128 					const RandomVariable &rho,
       
   129 					double x, double y)
       
   130   : m_theta (theta),
       
   131     m_rho (rho),
       
   132     m_x (0.0),
       
   133     m_y (0.0)
       
   134 {}
       
   135 RandomDiscPosition::~RandomDiscPosition ()
       
   136 {}
       
   137 Vector
       
   138 RandomDiscPosition::Get (void) const
       
   139 {
       
   140   double theta = m_theta.GetValue ();
       
   141   double rho = m_rho.GetValue ();
       
   142   double x = m_x + std::cos (theta) * rho;
       
   143   double y = m_y + std::sin (theta) * rho;
       
   144   NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y);
       
   145   return Vector (x, y, 0.0);
       
   146 }
       
   147 
       
   148 
       
   149 } // namespace ns3