SUMO - Simulation of Urban MObility
GeomHelper.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // Some static methods performing geometrical operations
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 #ifndef GeomHelper_h
24 #define GeomHelper_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <cmath>
37 #include "Position.h"
38 #include "PositionVector.h"
40 
41 #ifndef M_PI
42 #define M_PI 3.1415926535897932384626433832795
43 #endif
44 
45 #define DEG2RAD(x) static_cast<SUMOReal>((x) * M_PI / 180.)
46 #define RAD2DEG(x) static_cast<SUMOReal>((x) * 180. / M_PI)
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
55 class GeomHelper {
56 
57 public:
59  static const SUMOReal INVALID_OFFSET;
60 
70  static void findLineCircleIntersections(const Position& c, SUMOReal radius, const Position& p1, const Position& p2,
71  std::vector<SUMOReal>& into);
72 
73 
78  static SUMOReal angle2D(const Position& p1, const Position& p2);
79 
81  const Position& lineStart, const Position& lineEnd,
82  const Position& p, bool perpendicular = true);
83 
84  static Position crossPoint(const Boundary& b,
85  const PositionVector& v);
86 
92  static SUMOReal getCCWAngleDiff(SUMOReal angle1, SUMOReal angle2);
93 
94 
100  static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2);
101 
102 
108  static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2);
109 
110 
120  static SUMOReal angleDiff(const SUMOReal angle1, const SUMOReal angle2);
121 
122 
129  static SUMOReal naviDegree(const SUMOReal angle);
130 
137  static SUMOReal legacyDegree(const SUMOReal angle, const bool positive = false);
138 
139 };
140 
141 
142 #endif
143 
144 /****************************************************************************/
static SUMOReal angle2D(const Position &p1, const Position &p2)
Returns the angle between two vectors on a plane The angle is from vector 1 to vector 2...
Definition: GeomHelper.cpp:94
static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the distance of second angle from first angle clockwise.
Definition: GeomHelper.cpp:162
static SUMOReal getCCWAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the distance of second angle from first angle counter-clockwise.
Definition: GeomHelper.cpp:152
static Position crossPoint(const Boundary &b, const PositionVector &v)
Definition: GeomHelper.cpp:127
static SUMOReal angleDiff(const SUMOReal angle1, const SUMOReal angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:178
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
static SUMOReal legacyDegree(const SUMOReal angle, const bool positive=false)
Definition: GeomHelper.cpp:204
Some static methods performing geometrical operations.
Definition: GeomHelper.h:55
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
static void findLineCircleIntersections(const Position &c, SUMOReal radius, const Position &p1, const Position &p2, std::vector< SUMOReal > &into)
Returns the positions the given circle is crossed by the given line.
Definition: GeomHelper.cpp:58
static SUMOReal naviDegree(const SUMOReal angle)
Definition: GeomHelper.cpp:191
static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:172
static SUMOReal nearest_offset_on_line_to_point2D(const Position &lineStart, const Position &lineEnd, const Position &p, bool perpendicular=true)
Definition: GeomHelper.cpp:100
#define SUMOReal
Definition: config.h:214
static const SUMOReal INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition: GeomHelper.h:59