aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2012-03-26 18:30:04 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2012-03-26 18:30:04 +0200
commitfd2f399c1839fedc63ea8abe47feae6e42b6ad96 (patch)
tree5599f2b511d6079e97a89f7ca0e0d3ef38f90a98 /Eigen
parent6c3b8b2ebc9545466efb76f74146f860651f818f (diff)
fix bug #439: add Quaternion::FromTwoVectors() static constructor
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/src/Geometry/Quaternion.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h
index 2da0a541f..0b001ef07 100644
--- a/Eigen/src/Geometry/Quaternion.h
+++ b/Eigen/src/Geometry/Quaternion.h
@@ -284,6 +284,9 @@ public:
explicit inline Quaternion(const Quaternion<OtherScalar, OtherOptions>& other)
{ m_coeffs = other.coeffs().template cast<Scalar>(); }
+ template<typename Derived1, typename Derived2>
+ static Quaternion FromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b);
+
inline Coefficients& coeffs() { return m_coeffs;}
inline const Coefficients& coeffs() const { return m_coeffs;}
@@ -624,6 +627,27 @@ inline Derived& QuaternionBase<Derived>::setFromTwoVectors(const MatrixBase<Deri
return derived();
}
+
+/** Returns a quaternion representing a rotation between
+ * the two arbitrary vectors \a a and \a b. In other words, the built
+ * rotation represent a rotation sending the line of direction \a a
+ * to the line of direction \a b, both lines passing through the origin.
+ *
+ * \returns resulting quaternion
+ *
+ * Note that the two input vectors do \b not have to be normalized, and
+ * do not need to have the same norm.
+ */
+template<typename Scalar, int Options>
+template<typename Derived1, typename Derived2>
+Quaternion<Scalar,Options> Quaternion<Scalar,Options>::FromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b)
+{
+ Quaternion quat;
+ quat.setFromTwoVectors(a, b);
+ return quat;
+}
+
+
/** \returns the multiplicative inverse of \c *this
* Note that in most cases, i.e., if you simply want the opposite rotation,
* and/or the quaternion is normalized, then it is enough to use the conjugate.