25 double X = 0, Y = 0, Z = 0;
27 for (
int i = startIndex; i < endIndex; i++)
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]);
42 alpha = M_PI * 3.0 / 4.0;
49 alpha = - atan(2.0 * Z / (Y - X)) * 0.5;
56 alpha = M_PI / 2.0 - atan(2.0 * Z / (Y - X)) * 0.5;
66 for (
int i = startIndex; i < endIndex; i++)
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])));
72 variance /= (double)functionPoints->size();
74 result.
approximatedVector = Eigen::Vector2d(cos(alpha) * maxLength, sin(alpha) * maxLength);
Eigen::Vector2d approximatedVector
ApproximationResult calculateApproximation(Eigen::Vector2d *functionPoints, int startIndex, int endIndex, Eigen::Vector2d centerOffset)