quick reimplementation of SVD from the numeral recipes book:

this is still not Eigen style code but at least it works for
n>m and it is more accurate than the JAMA based version. (I needed
it now, this is why I did that)
This commit is contained in:
Gael Guennebaud
2009-07-06 13:47:41 +02:00
parent 0cd158820c
commit 0c2232e5d9
3 changed files with 254 additions and 350 deletions

View File

@@ -371,13 +371,14 @@ inline Quaternion<Scalar>& Quaternion<Scalar>::setFromTwoVectors(const MatrixBas
if (ei_isApprox(c,Scalar(-1)))
{
c = std::max<Scalar>(c,-1);
SVD<Matrix<Scalar,3,3> > svd(v0 * v0.transpose() + v1 * v1.transpose());
Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose();
SVD<Matrix<Scalar,2,3> > svd(m);
Vector3 axis = svd.matrixV().col(2);
Scalar w2 = (Scalar(1)+c)*Scalar(0.5);
this->w() = ei_sqrt(w2);
this->vec() = axis * ei_sqrt(Scalar(1) - w2);
return *this;
}