Eclipse SUMO - Simulation of Urban MObility
GeomHelper.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Some static methods performing geometrical operations
18 /****************************************************************************/
19 #ifndef GeomHelper_h
20 #define GeomHelper_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <cmath>
29 #include "Position.h"
30 #include "PositionVector.h"
32 
33 #ifndef M_PI
34 #define M_PI 3.1415926535897932384626433832795
35 #endif
36 
37 #define DEG2RAD(x) static_cast<double>((x) * M_PI / 180.)
38 #define RAD2DEG(x) static_cast<double>((x) * 180. / M_PI)
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
47 class GeomHelper {
48 
49 public:
51  static const double INVALID_OFFSET;
52 
62  static void findLineCircleIntersections(const Position& c, double radius, const Position& p1, const Position& p2,
63  std::vector<double>& into);
64 
65 
70  static double angle2D(const Position& p1, const Position& p2);
71 
73  const Position& lineStart, const Position& lineEnd,
74  const Position& p, bool perpendicular = true);
75 
77  const Position& lineStart, const Position& lineEnd,
78  const Position& p, bool perpendicular = true);
79 
80  static Position crossPoint(const Boundary& b,
81  const PositionVector& v);
82 
88  static double getCCWAngleDiff(double angle1, double angle2);
89 
90 
96  static double getCWAngleDiff(double angle1, double angle2);
97 
98 
104  static double getMinAngleDiff(double angle1, double angle2);
105 
106 
116  static double angleDiff(const double angle1, const double angle2);
117 
118 
125  static double naviDegree(const double angle);
126 
132  static double fromNaviDegree(const double angle);
133 
140  static double legacyDegree(const double angle, const bool positive = false);
141 
148  static PositionVector makeCircle(const double radius, const Position& center, unsigned int nPoints);
149 
157  static PositionVector makeRing(const double radius1, const double radius2, const Position& center, unsigned int nPoints);
158 
159 };
160 
161 
162 #endif
163 
164 /****************************************************************************/
GeomHelper::angleDiff
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:180
GeomHelper::getMinAngleDiff
static double getMinAngleDiff(double angle1, double angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:174
GeomHelper::nearest_offset_on_line_to_point25D
static double nearest_offset_on_line_to_point25D(const Position &lineStart, const Position &lineEnd, const Position &p, bool perpendicular=true)
Definition: GeomHelper.cpp:116
GeomHelper::legacyDegree
static double legacyDegree(const double angle, const bool positive=false)
Definition: GeomHelper.cpp:216
GeomHelper::naviDegree
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:193
GeomHelper::nearest_offset_on_line_to_point2D
static double nearest_offset_on_line_to_point2D(const Position &lineStart, const Position &lineEnd, const Position &p, bool perpendicular=true)
Definition: GeomHelper.cpp:89
PositionVector
A list of positions.
Definition: PositionVector.h:45
GeomHelper::makeRing
static PositionVector makeRing(const double radius1, const double radius2, const Position &center, unsigned int nPoints)
Definition: GeomHelper.cpp:254
GeomHelper::INVALID_OFFSET
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition: GeomHelper.h:51
GeomHelper::crossPoint
static Position crossPoint(const Boundary &b, const PositionVector &v)
Definition: GeomHelper.cpp:129
GeomHelper::findLineCircleIntersections
static void findLineCircleIntersections(const Position &c, double radius, const Position &p1, const Position &p2, std::vector< double > &into)
Returns the positions the given circle is crossed by the given line.
Definition: GeomHelper.cpp:47
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
UtilExceptions.h
GeomHelper
Some static methods performing geometrical operations.
Definition: GeomHelper.h:47
GeomHelper::getCWAngleDiff
static double getCWAngleDiff(double angle1, double angle2)
Returns the distance of second angle from first angle clockwise.
Definition: GeomHelper.cpp:164
Position.h
GeomHelper::angle2D
static double 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:83
GeomHelper::fromNaviDegree
static double fromNaviDegree(const double angle)
Definition: GeomHelper.cpp:210
GeomHelper::makeCircle
static PositionVector makeCircle(const double radius, const Position &center, unsigned int nPoints)
Definition: GeomHelper.cpp:237
config.h
PositionVector.h
GeomHelper::getCCWAngleDiff
static double getCCWAngleDiff(double angle1, double angle2)
Returns the distance of second angle from first angle counter-clockwise.
Definition: GeomHelper.cpp:154