diff options
author | 2009-02-17 09:53:05 +0000 | |
---|---|---|
committer | 2009-02-17 09:53:05 +0000 | |
commit | e6f1104b57f19dff773b4f22d26d6aacabd1bdb2 (patch) | |
tree | 5de1c7a6d6eb47d894f119b5bda0107bd531000d /Eigen/src/Geometry/Quaternion.h | |
parent | 67b4fab4e30a59d9a7e001ef25938d1767371569 (diff) |
* fix Quaternion::setFromTwoVectors (thanks to "benv" from the forum)
* extend PartialRedux::cross() to any matrix sizes with automatic
vectorization when possible
* unit tests: add "geo_" prefix to all unit tests related to the
geometry module and start splitting the big "geometry.cpp" tests to
multiple smaller ones (also include new tests)
Diffstat (limited to 'Eigen/src/Geometry/Quaternion.h')
-rw-r--r-- | Eigen/src/Geometry/Quaternion.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h index e72ce814f..0305fe176 100644 --- a/Eigen/src/Geometry/Quaternion.h +++ b/Eigen/src/Geometry/Quaternion.h @@ -345,7 +345,6 @@ inline Quaternion<Scalar>& Quaternion<Scalar>::setFromTwoVectors(const MatrixBas { Vector3 v0 = a.normalized(); Vector3 v1 = b.normalized(); - Vector3 axis = v0.cross(v1); Scalar c = v0.dot(v1); // if dot == 1, vectors are the same @@ -353,7 +352,17 @@ inline Quaternion<Scalar>& Quaternion<Scalar>::setFromTwoVectors(const MatrixBas { // set to identity this->w() = 1; this->vec().setZero(); + return *this; } + // if dot == -1, vectors are opposites + if (ei_isApprox(c,Scalar(-1))) + { + this->vec() = v0.unitOrthogonal(); + this->w() = 0; + return *this; + } + + Vector3 axis = v0.cross(v1); Scalar s = ei_sqrt((Scalar(1)+c)*Scalar(2)); Scalar invs = Scalar(1)/s; this->vec() = axis * invs; |