|
SUMO - Simulation of Urban MObility
|
00001 /************************************************************************ 00002 * * 00003 * Copyright 2004, Brown University, Providence, RI * 00004 * * 00005 * Permission to use and modify this software and its documentation * 00006 * for any purpose other than its incorporation into a commercial * 00007 * product is hereby granted without fee. Recipient agrees not to * 00008 * re-distribute this software or any modifications of this * 00009 * software without the permission of Brown University. Brown * 00010 * University makes no representations or warrantees about the * 00011 * suitability of this software for any purpose. It is provided * 00012 * "as is" without express or implied warranty. Brown University * 00013 * requests notification of any modifications to this software or * 00014 * its documentation. Notice should be sent to: * 00015 * * 00016 * To: * 00017 * Software Librarian * 00018 * Laboratory for Engineering Man/Machine Systems, * 00019 * Division of Engineering, Box D, * 00020 * Brown University * 00021 * Providence, RI 02912 * 00022 * Software_Librarian@lems.brown.edu * 00023 * * 00024 * We will acknowledge all electronic notifications. * 00025 * * 00026 ************************************************************************/ 00027 00028 #ifndef EULER_H 00029 #define EULER_H 00030 00031 // Rewritten by Amir: Feb 1, 2004 00032 00033 #include "angles.h" 00034 #include "BiArc.h" 00035 #include <vector> 00036 00037 //some defines for Euler-spiral optimization 00038 #define MAX_NUM_ITERATIONS 50000 00039 #define eError 1e-5 00040 00041 class EulerSpiralParams; 00042 class EulerSpiralLookupTable; 00043 class EulerSpiral; 00044 00045 class EulerSpiralParams 00046 { 00047 public: 00048 Point2D<double> start_pt; 00049 Point2D<double> end_pt; 00050 00051 double start_angle; 00052 double end_angle; 00053 double K0; 00054 double K2; 00055 double gamma; 00056 double L; 00057 double turningAngle; 00058 double error; 00059 double psi; 00060 00061 EulerSpiralParams() 00062 { 00063 start_angle = 0; 00064 end_angle = 0; 00065 K0 = 0; 00066 K2 = 0; 00067 gamma = 0; 00068 L = 0; 00069 turningAngle = 0; 00070 error = 0; 00071 psi = 0; 00072 } 00073 00074 ~EulerSpiralParams(){}; 00075 00076 EulerSpiralParams(const EulerSpiralParams &rhs) 00077 { 00078 start_pt = rhs.start_pt; 00079 end_pt = rhs.end_pt; 00080 start_angle = rhs.start_angle; 00081 end_angle = rhs.end_angle; 00082 K0 = rhs.K0; 00083 K2 = rhs.K2; 00084 gamma = rhs.gamma; 00085 L = rhs.L; 00086 turningAngle = rhs.turningAngle; 00087 error = rhs.error; 00088 psi = rhs.psi; 00089 } 00090 00091 EulerSpiralParams& operator=(const EulerSpiralParams &rhs) 00092 { 00093 if (this!=&rhs) 00094 { 00095 start_pt = rhs.start_pt; 00096 end_pt = rhs.end_pt; 00097 start_angle = rhs.start_angle; 00098 end_angle = rhs.end_angle; 00099 K0 = rhs.K0; 00100 K2 = rhs.K2; 00101 gamma = rhs.gamma; 00102 L = rhs.L; 00103 turningAngle = rhs.turningAngle; 00104 error = rhs.error; 00105 psi = rhs.psi; 00106 } 00107 return *this; 00108 } 00109 }; 00110 00111 class EulerSpiralLookupTable 00112 { 00113 private: 00114 int NN; //size of the lookup tables (NNxNN) or number of data points between -pi and pi 00115 double* _theta; //lookup the theta value corresponding to the index NN long 00116 double _dt; //delta theta 00117 00118 //lookup tables read in from files 00119 double** ES_k0; 00120 double** ES_k1; 00121 double** ES_gamma; 00122 double** ES_L; 00123 00124 public: 00125 EulerSpiralLookupTable(); 00126 ~EulerSpiralLookupTable(); 00127 00128 static EulerSpiralLookupTable* get_globalEulerSpiralLookupTable(); 00129 00130 double k0(double start_angle, double end_angle); 00131 double k1(double start_angle, double end_angle); 00132 double gamma(double start_angle, double end_angle); 00133 double L(double start_angle, double end_angle); 00134 00135 double dt(); //delta theta values for the table (tells you about the accuracy of the lookup) 00136 double theta(int N); //lookup the theta value indexed by N 00137 }; 00138 00139 class EulerSpiral 00140 { 00141 private: 00142 BiArc _bi_arc_estimate; 00143 00144 public: 00145 EulerSpiralParams params; 00146 std::vector <Point2D<double> > pts; 00147 00148 EulerSpiral(){}; 00149 00150 //constructor Type 1 00151 EulerSpiral(Point2D<double> start_pt, double start_angle, Point2D<double> end_pt, double end_angle) 00152 { 00153 params.start_pt = start_pt; 00154 params.start_angle = angle0To2Pi(start_angle); 00155 00156 params.end_pt = end_pt; 00157 params.end_angle = angle0To2Pi(end_angle); 00158 00159 //since we have all the parameters, we might as well compute it 00160 compute_es_params(); 00161 } 00162 00163 //Constructor type 2 00164 EulerSpiral(Point2D<double> start_pt, double start_angle, double k0, double gamma, double L) 00165 { 00166 params.start_pt = start_pt; 00167 params.start_angle = angle0To2Pi(start_angle); 00168 params.end_pt = compute_end_pt(k0, gamma, L); 00169 params.end_angle = start_angle + 0.5*gamma*L*L + k0*L; 00170 00171 //since we have all the parameters, we might as well compute it 00172 compute_es_params(); 00173 } 00174 00175 void set_start_params(Point2D<double> start_pt, double start_angle) 00176 { 00177 params.start_pt = start_pt; 00178 params.start_angle = angle0To2Pi(start_angle); 00179 } 00180 00181 void set_end_params(Point2D<double> end_pt, double end_angle) 00182 { 00183 params.end_pt = end_pt; 00184 params.end_angle = angle0To2Pi(end_angle); 00185 } 00186 00187 void set_params(Point2D<double> start_pt, double start_angle, Point2D<double> end_pt, double end_angle) 00188 { 00189 params.start_pt = start_pt; 00190 params.start_angle = angle0To2Pi(start_angle); 00191 00192 params.end_pt = end_pt; 00193 params.end_angle = angle0To2Pi(end_angle); 00194 } 00195 00196 void compute_es_params (); 00197 00198 //compute the extrinsic points 00199 void computeSpiral(std::vector<Point2D<double> > &spiral, double ds=0, int NPts=0); 00200 00201 // Supporting functions 00202 Point2D<double> get_fresnel_integral(double value); 00203 Point2D<double> compute_end_pt(double arclength, bool bNormalized=false); 00204 Point2D<double> compute_end_pt(double k0, double gamma, double L, bool bNormalized=false); 00205 Point2D<double> compute_es_point(EulerSpiralParams& es_params, double arclength, bool bNormalized=false); 00206 inline double compute_error(double k0, double L); 00207 00208 // function to output data 00209 // void write_es_info_to_file(vcl_ofstream & fp); 00210 }; 00211 00212 #endif 00213