SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Position.h
Go to the documentation of this file.
1
/****************************************************************************/
10
// A position in the 2D- or 3D-world
11
/****************************************************************************/
12
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13
// Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
14
/****************************************************************************/
15
//
16
// This file is part of SUMO.
17
// SUMO is free software: you can redistribute it and/or modify
18
// it under the terms of the GNU General Public License as published by
19
// the Free Software Foundation, either version 3 of the License, or
20
// (at your option) any later version.
21
//
22
/****************************************************************************/
23
#ifndef Position_h
24
#define Position_h
25
26
27
// ===========================================================================
28
// included modules
29
// ===========================================================================
30
#include <iostream>
31
#include <cmath>
32
33
#ifdef _MSC_VER
34
#include <
windows_config.h
>
35
#else
36
#include <
config.h
>
37
#endif
38
39
// ===========================================================================
40
// class definitions
41
// ===========================================================================
46
class
Position
{
47
public
:
49
Position
() :
myX
(0.0),
myY
(0.0),
myZ
(0.0) { }
50
52
Position
(
SUMOReal
x
,
SUMOReal
y
)
53
:
myX
(x),
myY
(y),
myZ
(0) { }
54
56
Position
(
SUMOReal
x
,
SUMOReal
y
,
SUMOReal
z
)
57
:
myX
(x),
myY
(y),
myZ
(z) { }
58
60
~Position
() { }
61
63
SUMOReal
x
()
const
{
64
return
myX
;
65
}
66
68
SUMOReal
y
()
const
{
69
return
myY
;
70
}
71
73
SUMOReal
z
()
const
{
74
return
myZ
;
75
}
76
78
void
set
(
SUMOReal
x
,
SUMOReal
y
) {
79
myX
=
x
;
80
myY
=
y
;
81
}
82
84
void
set
(
SUMOReal
x
,
SUMOReal
y
,
SUMOReal
z
) {
85
myX
=
x
;
86
myY
=
y
;
87
myZ
=
z
;
88
}
89
91
void
set
(
const
Position
& pos) {
92
myX
= pos.myX;
93
myY
= pos.myY;
94
myZ
= pos.myZ;
95
}
96
97
99
void
mul
(
SUMOReal
val) {
100
myX
*= val;
101
myY
*= val;
102
myZ
*= val;
103
}
104
106
void
mul
(
SUMOReal
mx,
SUMOReal
my) {
107
myX
*= mx;
108
myY
*= my;
109
}
110
112
void
mul
(
SUMOReal
mx,
SUMOReal
my,
SUMOReal
mz) {
113
myX
*= mx;
114
myY
*= my;
115
myZ
*= mz;
116
}
117
119
void
add
(
const
Position
& pos) {
120
myX
+= pos.
myX
;
121
myY
+= pos.
myY
;
122
myZ
+= pos.
myZ
;
123
}
124
126
void
add
(
SUMOReal
dx,
SUMOReal
dy) {
127
myX
+= dx;
128
myY
+= dy;
129
}
130
132
void
add
(
SUMOReal
dx,
SUMOReal
dy,
SUMOReal
dz) {
133
myX
+= dx;
134
myY
+= dy;
135
myZ
+= dz;
136
}
137
139
void
sub
(
SUMOReal
dx,
SUMOReal
dy) {
140
myX
-= dx;
141
myY
-= dy;
142
}
143
145
void
sub
(
SUMOReal
dx,
SUMOReal
dy,
SUMOReal
dz) {
146
myX
-= dx;
147
myY
-= dy;
148
myZ
-= dz;
149
}
150
152
void
sub
(
const
Position
& pos) {
153
myX
-= pos.
myX
;
154
myY
-= pos.
myY
;
155
myZ
-= pos.
myZ
;
156
}
157
158
void
norm2d
() {
159
SUMOReal
val = sqrt(
myX
*
myX
+
myY
*
myY
);
160
myX
=
myX
/ val;
161
myY = myY / val;
162
}
163
164
void
reshiftRotate
(
SUMOReal
xoff,
SUMOReal
yoff,
SUMOReal
rot) {
165
SUMOReal
x
=
myX
* cos(rot) -
myY
* sin(rot) + xoff;
166
SUMOReal
y
=
myX
* sin(rot) + yoff +
myY
* cos(rot);
167
myX
=
x
;
168
myY
=
y
;
169
}
170
171
173
friend
std::ostream&
operator<<
(std::ostream& os,
const
Position
& p) {
174
os << p.
x
() <<
","
<< p.
y
();
175
if
(p.
z
() !=
SUMOReal
(0.0)) {
176
os <<
","
<< p.
z
();
177
}
178
return
os;
179
}
180
181
Position
operator+
(
const
Position
& p2)
const
{
182
return
Position
(
myX
+ p2.
myX
,
myY
+ p2.
myY
,
myZ
+ p2.
myZ
);
183
}
184
185
Position
operator-
(
const
Position
& p2)
const
{
186
return
Position
(
myX
- p2.
myX
,
myY
- p2.
myY
,
myZ
- p2.
myZ
);
187
}
188
190
Position
operator*
(
SUMOReal
scalar)
const
{
191
return
Position
(
myX
* scalar,
myY
* scalar,
myZ
* scalar);
192
}
193
195
Position
operator+
(
SUMOReal
offset)
const
{
196
const
SUMOReal
length =
distanceTo
(
Position
(0, 0, 0));
197
if
(length == 0) {
198
return
*
this
;
199
}
200
const
SUMOReal
scalar = (length + offset) / length;
201
return
Position
(
myX
* scalar,
myY
* scalar,
myZ
* scalar);
202
}
203
204
bool
operator==
(
const
Position
& p2)
const
{
205
return
myX
== p2.
myX
&&
myY
== p2.
myY
&&
myZ
== p2.
myZ
;
206
}
207
208
bool
operator!=
(
const
Position
& p2)
const
{
209
return
myX
!= p2.
myX
||
myY
!= p2.
myY
||
myZ
!= p2.
myZ
;
210
}
211
213
bool
operator<
(
const
Position
& p2)
const
{
214
if
(
myX
< p2.
myX
) {
215
return
true
;
216
}
else
if
(
myY
< p2.
myY
) {
217
return
true
;
218
}
else
{
219
return
myZ
< p2.
myZ
;
220
}
221
}
222
223
bool
almostSame
(
const
Position
& p2,
SUMOReal
maxDiv =
POSITION_EPS
)
const
{
224
return
fabs(
myX
- p2.
myX
) < maxDiv && fabs(
myY
- p2.
myY
) < maxDiv && fabs(
myZ
- p2.
myZ
) < maxDiv;
225
}
226
227
229
inline
SUMOReal
distanceTo
(
const
Position
& p2)
const
{
230
return
sqrt(
distanceSquaredTo
(p2));
231
}
232
233
234
inline
SUMOReal
distanceSquaredTo
(
const
Position
& p2)
const
{
235
return
(
myX
- p2.
myX
) * (
myX
- p2.
myX
) + (
myY
- p2.
myY
) * (
myY
- p2.
myY
) + (
myZ
- p2.
myZ
) * (
myZ
- p2.
myZ
);
236
}
237
238
240
inline
SUMOReal
distanceTo2D
(
const
Position
& p2)
const
{
241
return
sqrt(
distanceSquaredTo2D
(p2));
242
}
243
244
245
inline
SUMOReal
distanceSquaredTo2D
(
const
Position
& p2)
const
{
246
return
(
myX
- p2.
myX
) * (
myX
- p2.
myX
) + (
myY
- p2.
myY
) * (
myY
- p2.
myY
);
247
}
248
250
Position
crossProduct
(
const
Position
& pos) {
251
return
Position
(
252
myY
* pos.
myZ
-
myZ
* pos.
myY
,
253
myZ
* pos.
myX
-
myX
* pos.
myZ
,
254
myX
* pos.
myY
-
myY
* pos.
myX
);
255
}
256
258
inline
SUMOReal
dotProduct
(
const
Position
& pos) {
259
return
myX
* pos.
myX
+
myY
* pos.
myY
+
myZ
* pos.
myZ
;
260
}
261
262
static
const
Position
INVALID
;
263
264
private
:
266
SUMOReal
myX
;
267
269
SUMOReal
myY
;
270
272
SUMOReal
myZ
;
273
274
};
275
276
277
#endif
278
279
/****************************************************************************/
280
tmp
buildd
sumo-0.21.0+dfsg
src
utils
geom
Position.h
Generated on Thu Nov 20 2014 19:49:58 for SUMO - Simulation of Urban MObility by
1.8.1.2