|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // Some mathematical helper methods 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #include <cmath> 00034 #include <string> 00035 #include <sstream> 00036 #include "NBNode.h" 00037 #include "NBHelpers.h" 00038 #include <utils/common/StringTokenizer.h> 00039 #include <utils/geom/Position.h> 00040 #include <utils/geom/GeomHelper.h> 00041 #include <iostream> 00042 00043 #ifdef CHECK_MEMORY_LEAKS 00044 #include <foreign/nvwa/debug_new.h> 00045 #endif // CHECK_MEMORY_LEAKS 00046 00047 00048 // =========================================================================== 00049 // method definitions 00050 // =========================================================================== 00051 SUMOReal 00052 NBHelpers::angle(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2) { 00053 SUMOReal angle = (SUMOReal) atan2(x1 - x2, y1 - y2) * (SUMOReal) 180.0 / (SUMOReal) PI; 00054 if (angle < 0) { 00055 angle = 360 + angle; 00056 } 00057 return angle; 00058 } 00059 00060 00061 SUMOReal 00062 NBHelpers::relAngle(SUMOReal angle, SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2) { 00063 SUMOReal sec_angle = NBHelpers::angle(x1, y1, x2, y2); 00064 return relAngle(angle, sec_angle); 00065 } 00066 00067 00068 SUMOReal 00069 NBHelpers::relAngle(SUMOReal angle1, SUMOReal angle2) { 00070 angle2 -= angle1; 00071 if (angle2 > 180) { 00072 angle2 = (360 - angle2) * -1; 00073 } 00074 while (angle2 < -180) { 00075 angle2 = 360 + angle2; 00076 } 00077 return angle2; 00078 } 00079 00080 00081 SUMOReal 00082 NBHelpers::normRelAngle(SUMOReal angle1, SUMOReal angle2) { 00083 SUMOReal rel = relAngle(angle1, angle2); 00084 if (rel < -170 || rel > 170) { 00085 rel = -180; 00086 } 00087 return rel; 00088 } 00089 00090 00091 std::string 00092 NBHelpers::normalIDRepresentation(const std::string& id) { 00093 std::stringstream strm1(id); 00094 long numid; 00095 strm1 >> numid; 00096 std::stringstream strm2; 00097 strm2 << numid; 00098 return strm2.str(); 00099 } 00100 00101 00102 SUMOReal 00103 NBHelpers::distance(NBNode* node1, NBNode* node2) { 00104 return node1->getPosition().distanceTo(node2->getPosition()); 00105 } 00106 00107 00108 00109 /****************************************************************************/