SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // Some geometrical helpers 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 #ifndef GeomHelper_h 00024 #define GeomHelper_h 00025 00026 00027 // =========================================================================== 00028 // included modules 00029 // =========================================================================== 00030 #ifdef _MSC_VER 00031 #include <windows_config.h> 00032 #else 00033 #include <config.h> 00034 #endif 00035 00036 #include "Position.h" 00037 #include "PositionVector.h" 00038 #include <utils/common/UtilExceptions.h> 00039 00040 00041 #ifndef PI 00042 #define PI 3.1415926535897932384626433832795 00043 #endif 00044 00045 // =========================================================================== 00046 // class definitions 00047 // =========================================================================== 00051 class GeomHelper { 00052 public: 00056 static bool intersects(const Position& p11, const Position& p12, 00057 const Position& p21, const Position& p22); 00058 00063 static Position intersection_position2D( 00064 const Position& p11, const Position& p12, 00065 const Position& p21, const Position& p22); 00066 00067 static SUMOReal Angle2D(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2); 00068 00069 static Position interpolate(const Position& p1, 00070 const Position& p2, SUMOReal length); 00071 00072 static Position extrapolate_first(const Position& p1, 00073 const Position& p2, SUMOReal length); 00074 00075 static Position extrapolate_second(const Position& p1, 00076 const Position& p2, SUMOReal length); 00077 00078 static SUMOReal nearest_position_on_line_to_point2D( 00079 const Position& l1, const Position& l2, 00080 const Position& p, bool perpendicular = true); 00081 00083 static SUMOReal distancePointLine(const Position& point, 00084 const Position& lineStart, const Position& lineEnd); 00085 00090 static SUMOReal closestDistancePointLine(const Position& point, 00091 const Position& lineStart, const Position& lineEnd, 00092 Position& outIntersection); 00093 00094 static Position transfer_to_side(Position& p, 00095 const Position& lineBeg, const Position& lineEnd, 00096 SUMOReal amount); 00097 00098 00099 static Position crossPoint(const Boundary& b, 00100 const PositionVector& v); 00101 00102 static std::pair<SUMOReal, SUMOReal> getNormal90D_CW(const Position& beg, 00103 const Position& end, SUMOReal length, SUMOReal wanted_offset); 00104 00105 static std::pair<SUMOReal, SUMOReal> getNormal90D_CW(const Position& beg, 00106 const Position& end, SUMOReal wanted_offset); 00107 00113 static SUMOReal getCCWAngleDiff(SUMOReal angle1, SUMOReal angle2) ; 00114 00115 00121 static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2) ; 00122 00123 00129 static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2) ; 00130 00131 00137 static SUMOReal getMaxAngleDiff(SUMOReal angle1, SUMOReal angle2) ; 00138 00139 00140 private: 00144 static bool intersects( 00145 const SUMOReal x1, const SUMOReal y1, const SUMOReal x2, const SUMOReal y2, 00146 const SUMOReal x3, const SUMOReal y3, const SUMOReal x4, const SUMOReal y4, 00147 SUMOReal* x, SUMOReal* y, SUMOReal* mu); 00148 00149 }; 00150 00151 00152 #endif 00153 00154 /****************************************************************************/