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 geometrical helpers
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2013 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 // class definitions
50 // ===========================================================================
54 class GeomHelper {
55 public:
59  static bool intersects(const Position& p11, const Position& p12,
60  const Position& p21, const Position& p22);
61 
67  const Position& p11, const Position& p12,
68  const Position& p21, const Position& p22);
69 
70  static SUMOReal Angle2D(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2);
71 
72  static Position interpolate(const Position& p1,
73  const Position& p2, SUMOReal length);
74 
75  static Position extrapolate_first(const Position& p1,
76  const Position& p2, SUMOReal length);
77 
78  static Position extrapolate_second(const Position& p1,
79  const Position& p2, SUMOReal length);
80 
82  const Position& l1, const Position& l2,
83  const Position& p, bool perpendicular = true);
84 
86  static SUMOReal distancePointLine(const Position& point,
87  const Position& lineStart, const Position& lineEnd);
88 
93  static SUMOReal closestDistancePointLine(const Position& point,
94  const Position& lineStart, const Position& lineEnd,
95  Position& outIntersection);
96 
98  const Position& lineBeg, const Position& lineEnd,
99  SUMOReal amount);
100 
101 
102  static Position crossPoint(const Boundary& b,
103  const PositionVector& v);
104 
105  static std::pair<SUMOReal, SUMOReal> getNormal90D_CW(const Position& beg,
106  const Position& end, SUMOReal length, SUMOReal wanted_offset);
107 
108  static std::pair<SUMOReal, SUMOReal> getNormal90D_CW(const Position& beg,
109  const Position& end, SUMOReal wanted_offset);
110 
116  static SUMOReal getCCWAngleDiff(SUMOReal angle1, SUMOReal angle2);
117 
118 
124  static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2);
125 
126 
132  static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2);
133 
134 
140  static SUMOReal getMaxAngleDiff(SUMOReal angle1, SUMOReal angle2);
141 
142 
143 private:
147  static bool intersects(
148  const SUMOReal x1, const SUMOReal y1, const SUMOReal x2, const SUMOReal y2,
149  const SUMOReal x3, const SUMOReal y3, const SUMOReal x4, const SUMOReal y4,
150  SUMOReal* x, SUMOReal* y, SUMOReal* mu);
151 
152 };
153 
154 
155 #endif
156 
157 /****************************************************************************/
static std::pair< SUMOReal, SUMOReal > getNormal90D_CW(const Position &beg, const Position &end, SUMOReal length, SUMOReal wanted_offset)
Definition: GeomHelper.cpp:310
static SUMOReal Angle2D(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2)
Definition: GeomHelper.cpp:161
static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the distance of second angle from first angle clockwise.
Definition: GeomHelper.cpp:332
static SUMOReal getCCWAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the distance of second angle from first angle counter-clockwise.
Definition: GeomHelper.cpp:322
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:140
static Position interpolate(const Position &p1, const Position &p2, SUMOReal length)
Definition: GeomHelper.cpp:174
static Position extrapolate_second(const Position &p1, const Position &p2, SUMOReal length)
Definition: GeomHelper.cpp:190
static Position extrapolate_first(const Position &p1, const Position &p2, SUMOReal length)
Definition: GeomHelper.cpp:182
static Position crossPoint(const Boundary &b, const PositionVector &v)
Definition: GeomHelper.cpp:277
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:198
static bool intersects(const Position &p11, const Position &p12, const Position &p21, const Position &p22)
return whether the line segments defined by Line p11,p12 and Line p21,p22 intersect ...
Definition: GeomHelper.cpp:132
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:261
A list of positions.
static SUMOReal distancePointLine(const Position &point, const Position &lineStart, const Position &lineEnd)
Definition: GeomHelper.cpp:225
static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:342
static SUMOReal getMaxAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the maximum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:348
#define SUMOReal
Definition: config.h:221
static SUMOReal closestDistancePointLine(const Position &point, const Position &lineStart, const Position &lineEnd, Position &outIntersection)
Definition: GeomHelper.cpp:249