ANYbotics / kindr

Kinematics and Dynamics for Robotics
BSD 3-Clause "New" or "Revised" License
551 stars 194 forks source link

Check the (Eigen based) fix operations #55

Open HannesSommer opened 9 years ago

HannesSommer commented 9 years ago

As suggested in https://github.com/ethz-asl/minkindr/pull/17/files#r22783093.

kruesip commented 9 years ago

Here's my Eigen implementation of a function finding the closest proper rotation matrix for a given input matrix:

Matrix3d rotationHealing(const Matrix3d& rotMat)  
{
   JacobiSVD<Matrix3d> svd(rotMat, ComputeFullV);

   Matrix3d correction = svd.matrixV().col(0) * svd.matrixV().col(0).transpose() / svd.singularValues()(0) +
                         svd.matrixV().col(1) * svd.matrixV().col(1).transpose() / svd.singularValues()(1) +
                         svd.matrixV().col(2) * svd.matrixV().col(2).transpose() / svd.singularValues()(2);

   return rotMat * correction;
}

The theory behind it is here: http://people.csail.mit.edu/bkph/articles/Nearest_Orthonormal_Matrix.pdf

Plus you need the following (copied from Wikipedia: http://en.wikipedia.org/wiki/Singular_value_decomposition):

HannesSommer commented 9 years ago

Ah, perfect. Thanks for providing that already :).