|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Some geometrical helpers 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef GeomHelper_h 00020 #define GeomHelper_h 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include "Position.h" 00033 #include "PositionVector.h" 00034 #include <utils/common/UtilExceptions.h> 00035 00036 00037 #ifndef PI 00038 #define PI 3.1415926535897932384626433832795 00039 #endif 00040 00041 // =========================================================================== 00042 // class definitions 00043 // =========================================================================== 00047 class GeomHelper { 00048 public: 00049 static bool intersects(SUMOReal x1b, SUMOReal y1b, SUMOReal x1e, SUMOReal y1e, 00050 SUMOReal x2b, SUMOReal y2b, SUMOReal x2e, SUMOReal y2e); 00051 00052 static bool intersects(const Position& p11, const Position& p12, 00053 const Position& p21, const Position& p22); 00054 00055 static Position intersection_position(const Position& p11, 00056 const Position& p12, const Position& p21, const Position& p22); 00057 00058 static SUMOReal Angle2D(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2); 00059 00060 static Position interpolate(const Position& p1, 00061 const Position& p2, SUMOReal length); 00062 00063 static Position extrapolate_first(const Position& p1, 00064 const Position& p2, SUMOReal length); 00065 00066 static Position extrapolate_second(const Position& p1, 00067 const Position& p2, SUMOReal length); 00068 00069 static SUMOReal nearest_position_on_line_to_point( 00070 const Position& l1, const Position& l2, 00071 const Position& p, bool perpendicular=true); 00072 00074 static SUMOReal distancePointLine(const Position& point, 00075 const Position& lineStart, const Position& lineEnd); 00076 00081 static SUMOReal closestDistancePointLine(const Position& point, 00082 const Position& lineStart, const Position& lineEnd, 00083 Position& outIntersection); 00084 00085 static Position transfer_to_side(Position& p, 00086 const Position& lineBeg, const Position& lineEnd, 00087 SUMOReal amount); 00088 00089 00090 static Position crossPoint(const Boundary& b, 00091 const PositionVector& v); 00092 00093 static std::pair<SUMOReal, SUMOReal> getNormal90D_CW(const Position& beg, 00094 const Position& end, SUMOReal length, SUMOReal wanted_offset); 00095 00096 static std::pair<SUMOReal, SUMOReal> getNormal90D_CW(const Position& beg, 00097 const Position& end, SUMOReal wanted_offset); 00098 00104 static SUMOReal getCCWAngleDiff(SUMOReal angle1, SUMOReal angle2) throw(); 00105 00106 00112 static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2) throw(); 00113 00114 00120 static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2) throw(); 00121 00122 00128 static SUMOReal getMaxAngleDiff(SUMOReal angle1, SUMOReal angle2) throw(); 00129 00130 00131 }; 00132 00133 00134 #endif 00135 00136 /****************************************************************************/ 00137