SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
euler.h
Go to the documentation of this file.
1 /************************************************************************
2  * *
3  * Copyright 2004, Brown University, Providence, RI *
4  * *
5  * Permission to use and modify this software and its documentation *
6  * for any purpose other than its incorporation into a commercial *
7  * product is hereby granted without fee. Recipient agrees not to *
8  * re-distribute this software or any modifications of this *
9  * software without the permission of Brown University. Brown *
10  * University makes no representations or warrantees about the *
11  * suitability of this software for any purpose. It is provided *
12  * "as is" without express or implied warranty. Brown University *
13  * requests notification of any modifications to this software or *
14  * its documentation. Notice should be sent to: *
15  * *
16  * To: *
17  * Software Librarian *
18  * Laboratory for Engineering Man/Machine Systems, *
19  * Division of Engineering, Box D, *
20  * Brown University *
21  * Providence, RI 02912 *
22  * Software_Librarian@lems.brown.edu *
23  * *
24  * We will acknowledge all electronic notifications. *
25  * *
26  ************************************************************************/
27 
28 #ifndef EULER_H
29 #define EULER_H
30 
31 // Rewritten by Amir: Feb 1, 2004
32 
33 #include "angles.h"
34 #include "BiArc.h"
35 #include <vector>
36 
37 //some defines for Euler-spiral optimization
38 #define MAX_NUM_ITERATIONS 50000
39 #define eError 1e-5
40 
41 class EulerSpiralParams;
43 class EulerSpiral;
44 
46 {
47 public:
50 
51  double start_angle;
52  double end_angle;
53  double K0;
54  double K2;
55  double gamma;
56  double L;
57  double turningAngle;
58  double error;
59  double psi;
60 
62  {
63  start_angle = 0;
64  end_angle = 0;
65  K0 = 0;
66  K2 = 0;
67  gamma = 0;
68  L = 0;
69  turningAngle = 0;
70  error = 0;
71  psi = 0;
72  }
73 
75 
77  {
78  start_pt = rhs.start_pt;
79  end_pt = rhs.end_pt;
81  end_angle = rhs.end_angle;
82  K0 = rhs.K0;
83  K2 = rhs.K2;
84  gamma = rhs.gamma;
85  L = rhs.L;
87  error = rhs.error;
88  psi = rhs.psi;
89  }
90 
92  {
93  if (this!=&rhs)
94  {
95  start_pt = rhs.start_pt;
96  end_pt = rhs.end_pt;
98  end_angle = rhs.end_angle;
99  K0 = rhs.K0;
100  K2 = rhs.K2;
101  gamma = rhs.gamma;
102  L = rhs.L;
104  error = rhs.error;
105  psi = rhs.psi;
106  }
107  return *this;
108  }
109 };
110 
112 {
113 private:
114  int NN; //size of the lookup tables (NNxNN) or number of data points between -pi and pi
115  double* _theta; //lookup the theta value corresponding to the index NN long
116  double _dt; //delta theta
117 
118  //lookup tables read in from files
119  double** ES_k0;
120  double** ES_k1;
121  double** ES_gamma;
122  double** ES_L;
123 
124 public:
127 
129 
130  double k0(double start_angle, double end_angle);
131  double k1(double start_angle, double end_angle);
132  double gamma(double start_angle, double end_angle);
133  double L(double start_angle, double end_angle);
134 
135  double dt(); //delta theta values for the table (tells you about the accuracy of the lookup)
136  double theta(int N); //lookup the theta value indexed by N
137 };
138 
140 {
141 private:
143 
144 public:
146  std::vector <Point2D<double> > pts;
147 
149 
150  //constructor Type 1
151  EulerSpiral(Point2D<double> start_pt, double start_angle, Point2D<double> end_pt, double end_angle)
152  {
153  params.start_pt = start_pt;
154  params.start_angle = angle0To2Pi(start_angle);
155 
156  params.end_pt = end_pt;
157  params.end_angle = angle0To2Pi(end_angle);
158 
159  //since we have all the parameters, we might as well compute it
161  }
162 
163  //Constructor type 2
164  EulerSpiral(Point2D<double> start_pt, double start_angle, double k0, double gamma, double L)
165  {
166  params.start_pt = start_pt;
167  params.start_angle = angle0To2Pi(start_angle);
168  params.end_pt = compute_end_pt(k0, gamma, L);
169  params.end_angle = start_angle + 0.5*gamma*L*L + k0*L;
170 
171  //since we have all the parameters, we might as well compute it
173  }
174 
175  void set_start_params(Point2D<double> start_pt, double start_angle)
176  {
177  params.start_pt = start_pt;
178  params.start_angle = angle0To2Pi(start_angle);
179  }
180 
181  void set_end_params(Point2D<double> end_pt, double end_angle)
182  {
183  params.end_pt = end_pt;
184  params.end_angle = angle0To2Pi(end_angle);
185  }
186 
187  void set_params(Point2D<double> start_pt, double start_angle, Point2D<double> end_pt, double end_angle)
188  {
189  params.start_pt = start_pt;
190  params.start_angle = angle0To2Pi(start_angle);
191 
192  params.end_pt = end_pt;
193  params.end_angle = angle0To2Pi(end_angle);
194  }
195 
196  void compute_es_params ();
197 
198  //compute the extrinsic points
199  void computeSpiral(std::vector<Point2D<double> > &spiral, double ds=0, int NPts=0);
200 
201  // Supporting functions
203  Point2D<double> compute_end_pt(double arclength, bool bNormalized=false);
204  Point2D<double> compute_end_pt(double k0, double gamma, double L, bool bNormalized=false);
205  Point2D<double> compute_es_point(EulerSpiralParams& es_params, double arclength, bool bNormalized=false);
206  inline double compute_error(double k0, double L);
207 
208  // function to output data
209 // void write_es_info_to_file(vcl_ofstream & fp);
210 };
211 
212 #endif
213