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
NBHelpers.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// Some mathematical helper methods
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13
/****************************************************************************/
14
//
15
// This file is part of SUMO.
16
// SUMO is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU General Public License as published by
18
// the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
/****************************************************************************/
22
23
24
// ===========================================================================
25
// included modules
26
// ===========================================================================
27
#ifdef _MSC_VER
28
#include <
windows_config.h
>
29
#else
30
#include <
config.h
>
31
#endif
32
33
#include <cmath>
34
#include <string>
35
#include <sstream>
36
#include "
NBNode.h
"
37
#include "
NBHelpers.h
"
38
#include <
utils/common/StringTokenizer.h
>
39
#include <
utils/geom/Position.h
>
40
#include <
utils/geom/GeomHelper.h
>
41
#include <iostream>
42
43
#ifdef CHECK_MEMORY_LEAKS
44
#include <
foreign/nvwa/debug_new.h
>
45
#endif // CHECK_MEMORY_LEAKS
46
47
48
// ===========================================================================
49
// method definitions
50
// ===========================================================================
51
SUMOReal
52
NBHelpers::angle
(
SUMOReal
x1,
SUMOReal
y1,
SUMOReal
x2,
SUMOReal
y2) {
53
SUMOReal
angle
= (
SUMOReal
) atan2(x1 - x2, y1 - y2) * (
SUMOReal
) 180.0 / (
SUMOReal
)
PI
;
54
if
(angle < 0) {
55
angle = 360 +
angle
;
56
}
57
return
angle
;
58
}
59
60
61
SUMOReal
62
NBHelpers::relAngle
(
SUMOReal
angle1,
SUMOReal
angle2) {
63
angle2 -= angle1;
64
if
(angle2 > 180) {
65
angle2 = (360 - angle2) * -1;
66
}
67
while
(angle2 < -180) {
68
angle2 = 360 + angle2;
69
}
70
return
angle2;
71
}
72
73
74
SUMOReal
75
NBHelpers::normRelAngle
(
SUMOReal
angle1,
SUMOReal
angle2) {
76
SUMOReal
rel =
relAngle
(angle1, angle2);
77
if
(rel < -170 || rel > 170) {
78
rel = -180;
79
}
80
return
rel;
81
}
82
83
84
std::string
85
NBHelpers::normalIDRepresentation
(
const
std::string&
id
) {
86
std::stringstream strm1(
id
);
87
long
numid;
88
strm1 >> numid;
89
std::stringstream strm2;
90
strm2 << numid;
91
return
strm2.str();
92
}
93
94
95
SUMOReal
96
NBHelpers::distance
(
NBNode
* node1,
NBNode
* node2) {
97
return
node1->
getPosition
().
distanceTo
(node2->
getPosition
());
98
}
99
100
101
102
/****************************************************************************/
build
buildd
sumo-0.16.0~dfsg
src
netbuild
NBHelpers.cpp
Generated on Tue Apr 16 2013 01:32:18 for SUMO - Simulation of Urban MObility by
1.8.3.1