13 #include "../../include/ecl/statistics/covariance_ellipsoid.hpp"
25 using ecl::linear_algebra::Matrix2f;
26 using ecl::linear_algebra::Vector2f;
27 using ecl::linear_algebra::Matrix3f;
28 using ecl::linear_algebra::Vector3f;
30 using ecl::linear_algebra::Matrix2d;
31 using ecl::linear_algebra::Vector2d;
32 using ecl::linear_algebra::Matrix3d;
33 using ecl::linear_algebra::Vector3d;
58 float tmp = sqrtf((a+d)*(a+d)/4 - a*d + b*c);
59 ellipse_lengths << sqrtf((a+d)/2 + tmp), sqrtf((a+d)/2 - tmp);
68 ellipse_axes(0,0) = ellipse_lengths(0)*ellipse_lengths(0)-d;
69 ellipse_axes(1,0) = c;
70 ellipse_axes(0,1) = ellipse_lengths(1)*ellipse_lengths(1)-d;
71 ellipse_axes(1,1) = c;
73 ellipse_axes(0,0) = b;
74 ellipse_axes(1,0) = ellipse_lengths(0)*ellipse_lengths(0)-a;
75 ellipse_axes(0,1) = b;
76 ellipse_axes(1,1) = ellipse_lengths(1)*ellipse_lengths(1)-a;
90 ellipse_axes.block<2,1>(0,0).normalize();
91 ellipse_axes.block<2,1>(0,1).normalize();
94 double CovarianceEllipsoid<float,2>::rotation() {
95 return atan2f(ellipse_axes(1,0), ellipse_axes(0,0));
102 float angle = rotation();
120 t = atan2f( -(ellipse_lengths(0)/ellipse_lengths(1))*tanf(angle), 1.0 );
121 intercept_magnitudes(0) = fabsf(ellipse_lengths(0)*cosf(t)*cosf(angle) - ellipse_lengths(1)*sinf(t)*sinf(angle));
125 t = atan2f( (ellipse_lengths(0)/ellipse_lengths(1)), tanf(angle) );
126 intercept_magnitudes(1) = fabsf(ellipse_lengths(0)*cosf(t)*sinf(angle) + ellipse_lengths(1)*sinf(t)*sinf(angle));
128 return intercept_magnitudes;
154 double tmp = sqrt((a+d)*(a+d)/4 - a*d + b*c);
155 ellipse_lengths << sqrt((a+d)/2 + tmp), sqrt((a+d)/2 - tmp);
164 ellipse_axes(0,0) = ellipse_lengths(0)*ellipse_lengths(0)-d;
165 ellipse_axes(1,0) = c;
166 ellipse_axes(0,1) = ellipse_lengths(1)*ellipse_lengths(1)-d;
167 ellipse_axes(1,1) = c;
168 }
else if( b != 0 ) {
169 ellipse_axes(0,0) = b;
170 ellipse_axes(1,0) = ellipse_lengths(0)*ellipse_lengths(0)-a;
171 ellipse_axes(0,1) = b;
172 ellipse_axes(1,1) = ellipse_lengths(1)*ellipse_lengths(1)-a;
176 ellipse_axes << 1, 0,
179 ellipse_axes << 0, 1,
186 ellipse_axes.block(0,0,2,1).normalize();
187 ellipse_axes.block(0,1,2,1).normalize();
191 return atan2(ellipse_axes(1,0), ellipse_axes(0,0));
198 double angle = rotation();
216 t = atan2( -(ellipse_lengths(0)/ellipse_lengths(1))*tan(angle), 1.0 );
217 intercept_magnitudes(0) = fabs(ellipse_lengths(0)*cos(t)*cos(angle) - ellipse_lengths(1)*sin(t)*sin(angle));
221 t = atan2( (ellipse_lengths(0)/ellipse_lengths(1)), tan(angle) );
222 intercept_magnitudes(1) = fabs(ellipse_lengths(0)*cos(t)*sin(angle) + ellipse_lengths(1)*sin(t)*sin(angle));
224 return intercept_magnitudes;
242 Eigen::EigenSolver<Matrix3f> esolver(M);
244 ellipse_lengths[0] = sqrtf(esolver.pseudoEigenvalueMatrix()(0,0));
245 ellipse_lengths[1] = sqrtf(esolver.pseudoEigenvalueMatrix()(1,1));
246 ellipse_lengths[2] = sqrtf(esolver.pseudoEigenvalueMatrix()(2,2));
247 ellipse_axes = esolver.pseudoEigenvectors ();
252 ecl::linear_algebra::Vector3f
c0 = ellipse_axes.block<3,1>(0,0);
c0.normalize();
253 ecl::linear_algebra::Vector3f
c1 = ellipse_axes.block<3,1>(0,1);
c1.normalize();
254 ecl::linear_algebra::Vector3f
c2 = ellipse_axes.block<3,1>(0,2);
c2.normalize();
255 ecl::linear_algebra::Vector3f cc =
c0.cross(c1);
256 if (cc.dot(c2) < 0) {
257 ellipse_axes <<
c1,
c0,
c2;
258 double e = ellipse_lengths[0]; ellipse_lengths[0] = ellipse_lengths[1]; ellipse_lengths[1] = e;
260 ellipse_axes <<
c0,
c1,
c2;
274 Eigen::EigenSolver<Matrix3d> esolver(M);
276 ellipse_lengths[0] = sqrt(esolver.pseudoEigenvalueMatrix()(0,0));
277 ellipse_lengths[1] = sqrt(esolver.pseudoEigenvalueMatrix()(1,1));
278 ellipse_lengths[2] = sqrt(esolver.pseudoEigenvalueMatrix()(2,2));
279 ellipse_axes = esolver.pseudoEigenvectors ();
284 ecl::linear_algebra::Vector3d
c0 = ellipse_axes.block<3,1>(0,0);
c0.normalize();
285 ecl::linear_algebra::Vector3d
c1 = ellipse_axes.block<3,1>(0,1);
c1.normalize();
286 ecl::linear_algebra::Vector3d
c2 = ellipse_axes.block<3,1>(0,2);
c2.normalize();
287 ecl::linear_algebra::Vector3d cc =
c0.cross(c1);
288 if (cc.dot(c2) < 0) {
289 ellipse_axes <<
c1,
c0,
c2;
290 double e = ellipse_lengths[0]; ellipse_lengths[0] = ellipse_lengths[1]; ellipse_lengths[1] = e;
292 ellipse_axes <<
c0,
c1,
c2;