SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NBHelpers.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Some mathematical helper methods
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 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 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <cmath>
35 #include <string>
36 #include <sstream>
37 #include "NBNode.h"
38 #include "NBHelpers.h"
40 #include <utils/geom/Position.h>
41 #include <utils/geom/GeomHelper.h>
42 #include <iostream>
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
54  SUMOReal angle = RAD2DEG(atan2(x1 - x2, y1 - y2));
55  if (angle < 0) {
56  angle = 360 + angle;
57  }
58  return angle;
59 }
60 
61 
64  angle2 -= angle1;
65  if (angle2 > 180) {
66  angle2 = (360 - angle2) * -1;
67  }
68  while (angle2 < -180) {
69  angle2 = 360 + angle2;
70  }
71  return angle2;
72 }
73 
74 
77  SUMOReal rel = relAngle(angle1, angle2);
78  if (rel + NUMERICAL_EPS >= 180) {
79  return -180;
80  } else {
81  return rel;
82  }
83 }
84 
85 
86 std::string
87 NBHelpers::normalIDRepresentation(const std::string& id) {
88  std::stringstream strm1(id);
89  long numid;
90  strm1 >> numid;
91  std::stringstream strm2;
92  strm2 << numid;
93  return strm2.str();
94 }
95 
96 
99  return node1->getPosition().distanceTo(node2->getPosition());
100 }
101 
102 
103 
104 /****************************************************************************/
static SUMOReal normRelAngle(SUMOReal angle1, SUMOReal angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
Definition: NBHelpers.cpp:76
#define RAD2DEG(x)
Definition: GeomHelper.h:46
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:229
static std::string normalIDRepresentation(const std::string &id)
Definition: NBHelpers.cpp:87
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:239
static SUMOReal angle(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2)
Definition: NBHelpers.cpp:53
Represents a single node (junction) during network building.
Definition: NBNode.h:75
#define SUMOReal
Definition: config.h:218
static SUMOReal relAngle(SUMOReal angle1, SUMOReal angle2)
Definition: NBHelpers.cpp:63
#define NUMERICAL_EPS
Definition: config.h:162
static SUMOReal distance(NBNode *node1, NBNode *node2)
Definition: NBHelpers.cpp:98