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.sourceforge.net/
12 // Copyright (C) 2001-2013 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 = (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 
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 < -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 
97  return node1->getPosition().distanceTo(node2->getPosition());
98 }
99 
100 
101 
102 /****************************************************************************/