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.sourceforge.net/
13
// Copyright (C) 2001-2013 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
189
Position
operator*
(
SUMOReal
scalar)
const
{
190
return
Position
(
myX
* scalar,
myY
* scalar,
myZ
* scalar);
191
}
192
193
bool
operator==
(
const
Position
& p2)
const
{
194
return
myX
== p2.
myX
&&
myY
== p2.
myY
&&
myZ
== p2.
myZ
;
195
}
196
197
bool
operator!=
(
const
Position
& p2)
const
{
198
return
myX
!= p2.
myX
||
myY
!= p2.
myY
||
myZ
!= p2.
myZ
;
199
}
200
201
202
bool
almostSame
(
const
Position
& p2,
SUMOReal
maxDiv =
POSITION_EPS
)
const
{
203
return
fabs(
myX
- p2.
myX
) < maxDiv && fabs(
myY
- p2.
myY
) < maxDiv && fabs(
myZ
- p2.
myZ
) < maxDiv;
204
}
205
206
208
inline
SUMOReal
distanceTo
(
const
Position
& p2)
const
{
209
return
sqrt(
distanceSquaredTo
(p2));
210
}
211
212
213
inline
SUMOReal
distanceSquaredTo
(
const
Position
& p2)
const
{
214
return
(
myX
- p2.
myX
) * (
myX
- p2.
myX
) + (
myY
- p2.
myY
) * (
myY
- p2.
myY
) + (
myZ
- p2.
myZ
) * (
myZ
- p2.
myZ
);
215
}
216
217
219
inline
SUMOReal
distanceTo2D
(
const
Position
& p2)
const
{
220
return
sqrt(
distanceSquaredTo2D
(p2));
221
}
222
223
224
inline
SUMOReal
distanceSquaredTo2D
(
const
Position
& p2)
const
{
225
return
(
myX
- p2.
myX
) * (
myX
- p2.
myX
) + (
myY
- p2.
myY
) * (
myY
- p2.
myY
);
226
}
227
229
Position
crossProduct
(
const
Position
& pos) {
230
return
Position
(
231
myY
* pos.
myZ
-
myZ
* pos.
myY
,
232
myZ
* pos.
myX
-
myX
* pos.
myZ
,
233
myX
* pos.
myY
-
myY
* pos.
myX
);
234
}
235
237
inline
SUMOReal
dotProduct
(
const
Position
& pos) {
238
return
myX
* pos.
myX
+
myY
* pos.
myY
+
myZ
* pos.
myZ
;
239
}
240
241
static
const
Position
INVALID
;
242
243
private
:
245
SUMOReal
myX
;
246
248
SUMOReal
myY
;
249
251
SUMOReal
myZ
;
252
253
};
254
255
256
#endif
257
258
/****************************************************************************/
259
build
buildd
sumo-0.17.1~dfsg
src
utils
geom
Position.h
Generated on Sun Jun 16 2013 17:30:19 for SUMO - Simulation of Urban MObility by
1.8.3.1