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
Line.cpp
Go to the documentation of this file.
1
/****************************************************************************/
10
// }
11
/****************************************************************************/
12
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
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
24
25
// ===========================================================================
26
// included modules
27
// ===========================================================================
28
29
#ifdef _MSC_VER
30
#include <
windows_config.h
>
31
#else
32
#include <
config.h
>
33
#endif
34
35
#include "
Position.h
"
36
#include "
Line.h
"
37
#include "
GeomHelper.h
"
38
#include <
utils/common/ToString.h
>
39
40
#ifdef CHECK_MEMORY_LEAKS
41
#include <
foreign/nvwa/debug_new.h
>
42
#endif // CHECK_MEMORY_LEAKS
43
44
45
// ===========================================================================
46
// member method definitions
47
// ===========================================================================
48
49
Line::Line
() {}
50
51
52
Line::Line
(
const
Position
& p1,
const
Position
& p2)
53
: myP1(p1), myP2(p2) {}
54
55
56
Line::~Line
() {}
57
58
59
void
60
Line::extrapolateBy
(
SUMOReal
length) {
61
SUMOReal
factor = length /
myP1
.
distanceTo
(
myP2
);
62
Position
offset = (
myP2
-
myP1
) * factor;
63
myP1
.
sub
(offset);
64
myP2
.
add
(offset);
65
}
66
67
68
void
69
Line::extrapolateFirstBy
(
SUMOReal
length) {
70
myP1
=
GeomHelper::extrapolate_first
(
myP1
,
myP2
, length);
71
}
72
73
74
void
75
Line::extrapolateSecondBy
(
SUMOReal
length) {
76
myP2
=
GeomHelper::extrapolate_second
(
myP1
,
myP2
, length);
77
}
78
79
const
Position
&
80
Line::p1
()
const
{
81
return
myP1
;
82
}
83
84
85
const
Position
&
86
Line::p2
()
const
{
87
return
myP2
;
88
}
89
90
91
Position
92
Line::getPositionAtDistance
(
SUMOReal
offset)
const
{
93
const
SUMOReal
length
=
myP1
.
distanceTo
(
myP2
);
94
if
(length == 0) {
95
if
(offset != 0) {
96
throw
InvalidArgument
(
"Invalid offset "
+
toString
(offset) +
" for Line with length "
+
toString
(length));;
97
}
98
return
myP1
;
99
}
100
return
myP1
+ (
myP2
-
myP1
) * (offset / length);
101
}
102
103
104
Position
105
Line::getPositionAtDistance2D
(
SUMOReal
offset)
const
{
106
const
SUMOReal
length
=
myP1
.
distanceTo2D
(
myP2
);
107
if
(length == 0) {
108
if
(offset != 0) {
109
throw
InvalidArgument
(
"Invalid offset "
+
toString
(offset) +
" for Line with length "
+
toString
(length));;
110
}
111
return
myP1
;
112
}
113
return
myP1
+ (
myP2
-
myP1
) * (offset / length);
114
}
115
116
117
void
118
Line::move2side
(
SUMOReal
amount) {
119
std::pair<SUMOReal, SUMOReal> p =
GeomHelper::getNormal90D_CW
(
myP1
,
myP2
, amount);
120
myP1
.
add
(p.first, p.second);
121
myP2
.
add
(p.first, p.second);
122
}
123
124
125
std::vector<SUMOReal>
126
Line::intersectsAtLengths2D
(
const
PositionVector
& v) {
127
PositionVector
p = v.
intersectionPoints2D
(*
this
);
128
std::vector<SUMOReal> ret;
129
for
(
size_t
i = 0; i < p.size(); i++) {
130
ret.
push_back
(
myP1
.
distanceTo2D
(p[
int
(i)]));
131
}
132
return
ret;
133
}
134
135
136
SUMOReal
137
Line::atan2Angle
()
const
{
138
return
atan2(
myP1
.
x
() -
myP2
.
x
(),
myP1
.
y
() -
myP2
.
y
());
139
}
140
141
142
SUMOReal
143
Line::atan2DegreeAngle
()
const
{
144
return
RAD2DEG
(atan2(
myP1
.
x
() -
myP2
.
x
(),
myP1
.
y
() -
myP2
.
y
()));
145
}
146
147
148
SUMOReal
149
Line::atan2PositiveAngle
()
const
{
150
SUMOReal
angle =
atan2Angle
();
151
if
(angle < 0) {
152
angle = (
SUMOReal
)
M_PI
* (
SUMOReal
) 2.0 + angle;
153
}
154
return
angle;
155
}
156
157
158
SUMOReal
159
Line::atan2DegreeSlope
()
const
{
160
return
RAD2DEG
(atan2(
myP2
.
z
() -
myP1
.
z
(),
myP1
.
distanceTo2D
(
myP2
)));
161
}
162
163
164
Position
165
Line::intersectsAt
(
const
Line
& l)
const
{
166
return
GeomHelper::intersection_position2D
(
myP1
,
myP2
, l.
myP1
, l.
myP2
);
167
}
168
169
170
bool
171
Line::intersects
(
const
Line
& l)
const
{
172
return
GeomHelper::intersects
(
myP1
,
myP2
, l.
myP1
, l.
myP2
);
173
}
174
175
176
SUMOReal
177
Line::length2D
()
const
{
178
return
myP1
.
distanceTo2D
(
myP2
);
179
}
180
181
182
SUMOReal
183
Line::length
()
const
{
184
return
myP1
.
distanceTo
(
myP2
);
185
}
186
187
188
void
189
Line::add
(
SUMOReal
x,
SUMOReal
y) {
190
myP1
.
add
(x, y);
191
myP2
.
add
(x, y);
192
}
193
194
195
void
196
Line::add
(
const
Position
& p) {
197
myP1
.
add
(p.
x
(), p.
y
(), p.
z
());
198
myP2
.
add
(p.
x
(), p.
y
(), p.
z
());
199
}
200
201
202
void
203
Line::sub
(
SUMOReal
x,
SUMOReal
y) {
204
myP1
.
sub
(x, y);
205
myP2
.
sub
(x, y);
206
}
207
208
209
210
Line
&
211
Line::reverse
() {
212
Position
tmp(
myP1
);
213
myP1
=
myP2
;
214
myP2
= tmp;
215
return
*
this
;
216
}
217
218
219
SUMOReal
220
Line::intersectsAtLength2D
(
const
Line
& v) {
221
Position
pos =
222
GeomHelper::intersection_position2D
(
myP1
,
myP2
, v.
myP1
, v.
myP2
);
223
return
GeomHelper::nearest_offset_on_line_to_point2D
(
myP1
,
myP2
, pos);
224
}
225
226
227
void
228
Line::rotateAtP1
(
SUMOReal
rot) {
229
Position
p =
myP2
;
230
p.
sub
(
myP1
);
231
p.
reshiftRotate
(0, 0, rot);
232
p.
add
(
myP1
);
233
myP2
= p;
234
}
235
236
237
/****************************************************************************/
build
buildd
sumo-0.18~dfsg
src
utils
geom
Line.cpp
Generated on Wed Oct 23 2013 01:15:09 for SUMO - Simulation of Urban MObility by
1.8.4