SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
13 // Copyright (C) 2001-2014 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 public:
64  static bool intersects(const Position& p11, const Position& p12,
65  const Position& p21, const Position& p22);
66 
67 
74  static bool pointOnLine(const Position& p, const Position& from, const Position& to);
75 
76 
86  static void FindLineCircleIntersections(const Position& c, SUMOReal radius, const Position& p1, const Position& p2,
87  std::vector<SUMOReal>& into);
88 
89 
95  const Position& p11, const Position& p12,
96  const Position& p21, const Position& p22);
97 
98  static SUMOReal Angle2D(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2);
99 
100  static Position interpolate(const Position& p1,
101  const Position& p2, SUMOReal length);
102 
103  static Position extrapolate_first(const Position& p1,
104  const Position& p2, SUMOReal length);
105 
106  static Position extrapolate_second(const Position& p1,
107  const Position& p2, SUMOReal length);
108 
110  const Position& l1, const Position& l2,
111  const Position& p, bool perpendicular = true);
112 
114  static SUMOReal distancePointLine(const Position& point,
115  const Position& lineStart, const Position& lineEnd);
116 
121  static SUMOReal closestDistancePointLine(const Position& point,
122  const Position& lineStart, const Position& lineEnd,
123  Position& outIntersection);
124 
126  const Position& lineBeg, const Position& lineEnd,
127  SUMOReal amount);
128 
129 
130  static Position crossPoint(const Boundary& b,
131  const PositionVector& v);
132 
133  static std::pair<SUMOReal, SUMOReal> getNormal90D_CW(const Position& beg,
134  const Position& end, SUMOReal length, SUMOReal wanted_offset);
135 
136  static std::pair<SUMOReal, SUMOReal> getNormal90D_CW(const Position& beg,
137  const Position& end, SUMOReal wanted_offset);
138 
144  static SUMOReal getCCWAngleDiff(SUMOReal angle1, SUMOReal angle2);
145 
146 
152  static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2);
153 
154 
160  static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2);
161 
162 
168  static SUMOReal getMaxAngleDiff(SUMOReal angle1, SUMOReal angle2);
169 
170 
171 private:
175  static bool intersects(
176  const SUMOReal x1, const SUMOReal y1, const SUMOReal x2, const SUMOReal y2,
177  const SUMOReal x3, const SUMOReal y3, const SUMOReal x4, const SUMOReal y4,
178  SUMOReal* x, SUMOReal* y, SUMOReal* mu);
179 
180 };
181 
182 
183 #endif
184 
185 /****************************************************************************/
static std::pair< SUMOReal, SUMOReal > getNormal90D_CW(const Position &beg, const Position &end, SUMOReal length, SUMOReal wanted_offset)
Definition: GeomHelper.cpp:359
static SUMOReal Angle2D(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2)
Definition: GeomHelper.cpp:210
static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the distance of second angle from first angle clockwise.
Definition: GeomHelper.cpp:381
static SUMOReal getCCWAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the distance of second angle from first angle counter-clockwise.
Definition: GeomHelper.cpp:371
static Position intersection_position2D(const Position &p11, const Position &p12, const Position &p21, const Position &p22)
returns the intersection point of the (infinite) lines p11,p12 and p21,p22. If the given lines are pa...
Definition: GeomHelper.cpp:189
static Position interpolate(const Position &p1, const Position &p2, SUMOReal length)
Definition: GeomHelper.cpp:223
static Position extrapolate_second(const Position &p1, const Position &p2, SUMOReal length)
Definition: GeomHelper.cpp:239
static Position extrapolate_first(const Position &p1, const Position &p2, SUMOReal length)
Definition: GeomHelper.cpp:231
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:149
static Position crossPoint(const Boundary &b, const PositionVector &v)
Definition: GeomHelper.cpp:326
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
static SUMOReal nearest_offset_on_line_to_point2D(const Position &l1, const Position &l2, const Position &p, bool perpendicular=true)
Definition: GeomHelper.cpp:247
static bool intersects(const Position &p11, const Position &p12, const Position &p21, const Position &p22)
return whether given lines intersect
Definition: GeomHelper.cpp:131
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
static Position transfer_to_side(Position &p, const Position &lineBeg, const Position &lineEnd, SUMOReal amount)
Definition: GeomHelper.cpp:310
A list of positions.
static SUMOReal distancePointLine(const Position &point, const Position &lineStart, const Position &lineEnd)
Definition: GeomHelper.cpp:274
static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:391
static SUMOReal getMaxAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the maximum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:397
#define SUMOReal
Definition: config.h:215
static bool pointOnLine(const Position &p, const Position &from, const Position &to)
Returns whether the given point lies on the given line.
Definition: GeomHelper.cpp:139
static SUMOReal closestDistancePointLine(const Position &point, const Position &lineStart, const Position &lineEnd, Position &outIntersection)
Definition: GeomHelper.cpp:298