A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
constant-acceleration-mobility-model.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation;
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
*
16
* Author: Gustavo Carneiro <gjc@inescporto.pt>
17
*/
18
#include "
constant-acceleration-mobility-model.h
"
19
#include "ns3/simulator.h"
20
21
namespace
ns3 {
22
23
NS_OBJECT_ENSURE_REGISTERED
(ConstantAccelerationMobilityModel);
24
25
TypeId
ConstantAccelerationMobilityModel::GetTypeId
(
void
)
26
{
27
static
TypeId
tid =
TypeId
(
"ns3::ConstantAccelerationMobilityModel"
)
28
.
SetParent
<
MobilityModel
> ()
29
.AddConstructor<ConstantAccelerationMobilityModel> ();
30
return
tid;
31
}
32
33
ConstantAccelerationMobilityModel::ConstantAccelerationMobilityModel
()
34
{
35
}
36
37
ConstantAccelerationMobilityModel::~ConstantAccelerationMobilityModel
()
38
{
39
}
40
41
inline
Vector
42
ConstantAccelerationMobilityModel::DoGetVelocity
(
void
)
const
43
{
44
double
t = (
Simulator::Now
() -
m_baseTime
).GetSeconds ();
45
return
Vector
(
m_baseVelocity
.
x
+
m_acceleration
.
x
*t,
46
m_baseVelocity
.
y
+
m_acceleration
.
y
*t,
47
m_baseVelocity
.
z
+
m_acceleration
.
z
*t);
48
}
49
50
inline
Vector
51
ConstantAccelerationMobilityModel::DoGetPosition
(
void
)
const
52
{
53
double
t = (
Simulator::Now
() -
m_baseTime
).GetSeconds ();
54
double
half_t_square = t*t*0.5;
55
return
Vector
(
m_basePosition
.
x
+
m_baseVelocity
.
x
*t +
m_acceleration
.
x
*half_t_square,
56
m_basePosition
.
y
+
m_baseVelocity
.
y
*t +
m_acceleration
.
y
*half_t_square,
57
m_basePosition
.
z
+
m_baseVelocity
.
z
*t +
m_acceleration
.
z
*half_t_square);
58
}
59
60
void
61
ConstantAccelerationMobilityModel::DoSetPosition
(
const
Vector
&position)
62
{
63
m_baseVelocity
=
DoGetVelocity
();
64
m_baseTime
=
Simulator::Now
();
65
m_basePosition
= position;
66
NotifyCourseChange
();
67
}
68
69
void
70
ConstantAccelerationMobilityModel::SetVelocityAndAcceleration
(
const
Vector
&velocity,
71
const
Vector
&acceleration)
72
{
73
m_basePosition
=
DoGetPosition
();
74
m_baseTime
=
Simulator::Now
();
75
m_baseVelocity
= velocity;
76
m_acceleration
= acceleration;
77
NotifyCourseChange
();
78
}
79
80
81
}
// namespace ns3
src
mobility
model
constant-acceleration-mobility-model.cc
Generated on Tue May 14 2013 11:08:29 for ns-3 by
1.8.1.2