SUMO - Simulation of Urban MObility
 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-sim.org/
12 // Copyright (C) 2001-2014 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"
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 // ===========================================================================
53  SUMOReal angle = RAD2DEG(atan2(x1 - x2, y1 - y2));
54  if (angle < 0) {
55  angle = 360 + angle;
56  }
57  return angle;
58 }
59 
60 
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 
76  SUMOReal rel = relAngle(angle1, angle2);
77  if (rel + NUMERICAL_EPS >= 180) {
78  return -180;
79  } else {
80  return rel;
81  }
82 }
83 
84 
85 std::string
86 NBHelpers::normalIDRepresentation(const std::string& id) {
87  std::stringstream strm1(id);
88  long numid;
89  strm1 >> numid;
90  std::stringstream strm2;
91  strm2 << numid;
92  return strm2.str();
93 }
94 
95 
98  return node1->getPosition().distanceTo(node2->getPosition());
99 }
100 
101 
102 
103 /****************************************************************************/
static SUMOReal normRelAngle(SUMOReal angle1, SUMOReal angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
Definition: NBHelpers.cpp:75
#define RAD2DEG(x)
Definition: GeomHelper.h:46
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:219
static std::string normalIDRepresentation(const std::string &id)
Definition: NBHelpers.cpp:86
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:158
static SUMOReal angle(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2)
Definition: NBHelpers.cpp:52
Represents a single node (junction) during network building.
Definition: NBNode.h:74
#define SUMOReal
Definition: config.h:215
static SUMOReal relAngle(SUMOReal angle1, SUMOReal angle2)
Definition: NBHelpers.cpp:62
#define NUMERICAL_EPS
Definition: config.h:159
static SUMOReal distance(NBNode *node1, NBNode *node2)
Definition: NBHelpers.cpp:97