From 986f301233469e7dcf6015c27e383b2777d70819 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 5 Jan 2009 14:26:34 +0000 Subject: [PATCH] *add PartialRedux::cross() with unit test *add transform-from-matrices test *undo an unwanted change in Matrix --- Eigen/src/Array/PartialRedux.h | 28 ++++++++++++++++++++++++++++ Eigen/src/Core/Matrix.h | 2 +- test/geometry.cpp | 19 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Eigen/src/Array/PartialRedux.h b/Eigen/src/Array/PartialRedux.h index 612d9c250..6ce72291e 100644 --- a/Eigen/src/Array/PartialRedux.h +++ b/Eigen/src/Array/PartialRedux.h @@ -172,6 +172,8 @@ template class PartialRedux > Type; }; + typedef typename ExpressionType::PlainMatrixType CrossReturnType; + inline PartialRedux(const ExpressionType& matrix) : m_matrix(matrix) {} /** \internal */ @@ -245,6 +247,32 @@ template class PartialRedux const typename ReturnType::Type any() const { return _expression(); } + /** \returns a 3x3 matrix expression of the cross product + * of each column or row of the referenced expression with the \a other vector. + * + * \geometry_module + * + * \sa MatrixBase::cross() */ + template + const CrossReturnType cross(const MatrixBase& other) const + { + EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(CrossReturnType,3,3) + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3) + EIGEN_STATIC_ASSERT((ei_is_same_type::ret), + YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) + + if(Direction==Vertical) + return (CrossReturnType() + << _expression().col(0).cross(other), + _expression().col(1).cross(other), + _expression().col(2).cross(other)).finished(); + else + return (CrossReturnType() + << _expression().row(0).cross(other), + _expression().row(1).cross(other), + _expression().row(2).cross(other)).finished(); + } + protected: ExpressionTypeNested m_matrix; }; diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index bb2bc2e2a..4851036e4 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -119,7 +119,7 @@ struct ei_traits > template -struct ei_matrix_with_aligned_operator_new : public WithAlignedOperatorNew {}; +struct ei_matrix_with_aligned_operator_new : WithAlignedOperatorNew {}; template struct ei_matrix_with_aligned_operator_new {}; diff --git a/test/geometry.cpp b/test/geometry.cpp index 8c0d3b688..7f978f766 100644 --- a/test/geometry.cpp +++ b/test/geometry.cpp @@ -181,6 +181,13 @@ template void geometry(void) // More transform constructors, operator=, operator*= + Matrix3 mat3 = Matrix3::Random(); + Matrix4 mat4; + mat4 << mat3 , Vector3::Zero() , Vector4::Zero().transpose(); + Transform3 tmat3(mat3), tmat4(mat4); + tmat4.matrix()(3,3) = Scalar(1); + VERIFY_IS_APPROX(tmat3.matrix(), tmat4.matrix()); + Scalar a3 = ei_random(-M_PI, M_PI); Vector3 v3 = Vector3::Random().normalized(); AngleAxisx aa3(a3, v3); @@ -388,6 +395,18 @@ template void geometry(void) VERIFY_EULER(2,0,2, Z,X,Z); VERIFY_EULER(2,1,0, Z,Y,X); VERIFY_EULER(2,1,2, Z,Y,Z); + + // colwise/rowwise cross product + mat3.setRandom(); + Vector3 vec3 = Vector3::Random(); + Matrix3 mcross; + int i = ei_random(0,2); + mcross = mat3.colwise().cross(vec3); + VERIFY_IS_APPROX(mcross.col(i), mat3.col(i).cross(vec3)); + mcross = mat3.rowwise().cross(vec3); + VERIFY_IS_APPROX(mcross.row(i), mat3.row(i).cross(vec3)); + + } void test_geometry()