linearApproximator.cpp
Go to the documentation of this file.
1 
19 #ifndef Q_MOC_RUN
20 #include <ros/ros.h>
21 #endif
22 
23  ApproximationResult LinearApproximator::calculateApproximation(Eigen::Vector2d * functionPoints, int startIndex, int endIndex, Eigen::Vector2d centerOffset)
24  {
25  double X = 0, Y = 0, Z = 0;
26  double alpha;
27  for (int i = startIndex; i < endIndex; i++)
28  {
29  Eigen::Vector2d it = functionPoints[i];
30  X += (it[0] - centerOffset[0]) * (it[0] - centerOffset[0]);
31  Y += (it[1] - centerOffset[1]) * (it[1] - centerOffset[1]);
32  Z += (it[0] - centerOffset[0]) * (it[1] - centerOffset[1]);
33  }
34  if (X == Y)
35  {
36  if (Z > 0)
37  {
38  alpha = M_PI / 4.0;
39  }
40  else
41  {
42  alpha = M_PI * 3.0 / 4.0;
43  }
44  }
45  else
46  {
47  if (Y - X < 0)
48  {
49  alpha = - atan(2.0 * Z / (Y - X)) * 0.5;
50  //ROS_INFO_STREAM("Y - X < 0");
51  }
52  else
53  {
54  //ROS_INFO_STREAM("Y - X > 0");
55  //alpha = - atan(2.0 * Z / (Y - X)) * 0.5;
56  alpha = M_PI / 2.0 - atan(2.0 * Z / (Y - X)) * 0.5;
57  }
58  if (alpha < M_PI/2.0)
59  {
60  alpha += M_PI;
61  }
62  }
63 
64  double variance = 0;
65  double maxLength = 0;
66  for (int i = startIndex; i < endIndex; i++)
67  {
68  Eigen::Vector2d it = functionPoints[i];
69  variance += pow(sin(alpha) * (it[0] - centerOffset[0]) - cos(alpha) * (it[1] - centerOffset[1]), 2.0);
70  maxLength = std::max(maxLength, std::abs(cos(alpha) * (it[0] - centerOffset[0]) + sin(alpha) * (it[1] - centerOffset[1])));
71  }
72  variance /= (double)functionPoints->size();
73  ApproximationResult result;
74  result.approximatedVector = Eigen::Vector2d(cos(alpha) * maxLength, sin(alpha) * maxLength);
75  result.angle = alpha;
76  result.variance = variance;
77  return result;
78  }
79 /*
80  double LinearApproximator::calculateApproximation(std::vector<Eigen::Vector2d> * functionPoints)
81  {
82  long X = 0, Y = 0, Z = 0;
83  double alpha;
84  for (std::vector<Eigen::Vector2d>::iterator it = functionPoints->begin(); it < functionPoints->end(); it++)
85  {
86  X += it[0] * it[0];
87  Y += it[1] * it[1];
88  Z += it[0] * it[1];
89  }
90 
91  if (X == Y)
92  {
93  if (Z > 0)
94  {
95  alpha = M_PI / 4.0;
96  }
97  else
98  {
99  alpha = M_PI * 3.0 / 4.0;
100  }
101  }
102  else
103  {
104  if (Y - X < 0)
105  {
106  alpha = - atan(2.0 * (double)Z / (double)(Y - X)) * 0.5;
107  if (alpha < 0.0)
108  {
109  alpha += M_PI;
110  }
111  }
112  else
113  {
114  alpha = M_PI / 2.0 - atan(2.0 * (double)Z / (double)(Y - X)) * 0.5;
115  }
116  }
117 
118  variance = 0;
119  double maxLength = 0;
120  for (std::vector<Eigen::Vector2d>::iterator it = functionPoints->begin(); it < functionPoints->end(); it++)
121  {
122  variance += pow(sin(alpha) * it[0] + cos(alpha) * it[1], 2.0);
123  maxLength = max(maxLength, cos(alpha) * it[0] - sin(alpha) * it[1]);
124  }
125  approximatedVector = new Eigen::Vector2d(cos(alpha) * maxLength, sin(alpha) * maxLength);
126  variance /= (double)functionPoints->size();
127 
128  angle = alpha;
129  return variance;
130  }*/
Eigen::Vector2d approximatedVector
ApproximationResult calculateApproximation(Eigen::Vector2d *functionPoints, int startIndex, int endIndex, Eigen::Vector2d centerOffset)


asr_mild_calibration_tool
Author(s): Aumann Florian, Heller Florian, Meißner Pascal
autogenerated on Mon Dec 2 2019 03:11:43