mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-15 02:43:14 +08:00
*add PartialRedux::cross() with unit test
*add transform-from-matrices test *undo an unwanted change in Matrix
This commit is contained in:
parent
d316d4f393
commit
986f301233
@ -172,6 +172,8 @@ template<typename ExpressionType, int Direction> class PartialRedux
|
|||||||
> Type;
|
> Type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef typename ExpressionType::PlainMatrixType CrossReturnType;
|
||||||
|
|
||||||
inline PartialRedux(const ExpressionType& matrix) : m_matrix(matrix) {}
|
inline PartialRedux(const ExpressionType& matrix) : m_matrix(matrix) {}
|
||||||
|
|
||||||
/** \internal */
|
/** \internal */
|
||||||
@ -245,6 +247,32 @@ template<typename ExpressionType, int Direction> class PartialRedux
|
|||||||
const typename ReturnType<ei_member_any>::Type any() const
|
const typename ReturnType<ei_member_any>::Type any() const
|
||||||
{ return _expression(); }
|
{ 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<typename OtherDerived>
|
||||||
|
const CrossReturnType cross(const MatrixBase<OtherDerived>& 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<Scalar, typename OtherDerived::Scalar>::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:
|
protected:
|
||||||
ExpressionTypeNested m_matrix;
|
ExpressionTypeNested m_matrix;
|
||||||
};
|
};
|
||||||
|
@ -119,7 +119,7 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
|
|||||||
|
|
||||||
template<typename T, int Rows, int Cols, int Options,
|
template<typename T, int Rows, int Cols, int Options,
|
||||||
bool NeedsToAlign = ((Options&Matrix_AutoAlign) == Matrix_AutoAlign) && Rows!=Dynamic && Cols!=Dynamic && ((sizeof(T)*Rows*Cols)%16==0)>
|
bool NeedsToAlign = ((Options&Matrix_AutoAlign) == Matrix_AutoAlign) && Rows!=Dynamic && Cols!=Dynamic && ((sizeof(T)*Rows*Cols)%16==0)>
|
||||||
struct ei_matrix_with_aligned_operator_new : public WithAlignedOperatorNew {};
|
struct ei_matrix_with_aligned_operator_new : WithAlignedOperatorNew {};
|
||||||
|
|
||||||
template<typename T, int Rows, int Cols, int Options>
|
template<typename T, int Rows, int Cols, int Options>
|
||||||
struct ei_matrix_with_aligned_operator_new<T, Rows, Cols, Options, false> {};
|
struct ei_matrix_with_aligned_operator_new<T, Rows, Cols, Options, false> {};
|
||||||
|
@ -181,6 +181,13 @@ template<typename Scalar> void geometry(void)
|
|||||||
|
|
||||||
// More transform constructors, operator=, operator*=
|
// 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<Scalar>(-M_PI, M_PI);
|
Scalar a3 = ei_random<Scalar>(-M_PI, M_PI);
|
||||||
Vector3 v3 = Vector3::Random().normalized();
|
Vector3 v3 = Vector3::Random().normalized();
|
||||||
AngleAxisx aa3(a3, v3);
|
AngleAxisx aa3(a3, v3);
|
||||||
@ -388,6 +395,18 @@ template<typename Scalar> void geometry(void)
|
|||||||
VERIFY_EULER(2,0,2, Z,X,Z);
|
VERIFY_EULER(2,0,2, Z,X,Z);
|
||||||
VERIFY_EULER(2,1,0, Z,Y,X);
|
VERIFY_EULER(2,1,0, Z,Y,X);
|
||||||
VERIFY_EULER(2,1,2, Z,Y,Z);
|
VERIFY_EULER(2,1,2, Z,Y,Z);
|
||||||
|
|
||||||
|
// colwise/rowwise cross product
|
||||||
|
mat3.setRandom();
|
||||||
|
Vector3 vec3 = Vector3::Random();
|
||||||
|
Matrix3 mcross;
|
||||||
|
int i = ei_random<int>(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()
|
void test_geometry()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user