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