mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-30 17:40:05 +08:00
switch from eigensolver to SVD which seems to be more accurate with float
This commit is contained in:
parent
90f1e24579
commit
0cd158820c
@ -6,7 +6,7 @@
|
||||
#include "src/Core/util/DisableMSVCWarnings.h"
|
||||
|
||||
#include "Array"
|
||||
#include "QR"
|
||||
#include "SVD"
|
||||
#include <limits>
|
||||
|
||||
#ifndef M_PI
|
||||
|
@ -367,12 +367,14 @@ inline Quaternion<Scalar>& Quaternion<Scalar>::setFromTwoVectors(const MatrixBas
|
||||
// x^T v1 = 0
|
||||
// under the constraint:
|
||||
// ||x|| = 1
|
||||
// which yields an eigenvalue problem (or a SVD)
|
||||
// which yields a singular value problem
|
||||
if (ei_isApprox(c,Scalar(-1)))
|
||||
{
|
||||
c = std::max<Scalar>(c,-1);
|
||||
SelfAdjointEigenSolver<Matrix<Scalar,3,3> > eig(v0 * v0.transpose() + v1 * v1.transpose());
|
||||
Vector3 axis = eig.eigenvectors().col(0);
|
||||
|
||||
SVD<Matrix<Scalar,3,3> > svd(v0 * v0.transpose() + v1 * v1.transpose());
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user