aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2011-01-27 11:33:37 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2011-01-27 11:33:37 +0100
commite8d6a5ca8787153c1b7e4b9d3f520ee85df5d5c7 (patch)
tree8485080488271dc2289aebd9bf0ef1a956178d3f /Eigen
parent0bfb78c8240525a8065e008efad08498d572ef81 (diff)
fix cross product for complexes and add support for mixed real-complex cross products
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/src/Core/MatrixBase.h10
-rw-r--r--Eigen/src/Geometry/OrthoMethods.h28
2 files changed, 23 insertions, 15 deletions
diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h
index f318bfd5d..096438f96 100644
--- a/Eigen/src/Core/MatrixBase.h
+++ b/Eigen/src/Core/MatrixBase.h
@@ -399,8 +399,16 @@ template<typename Derived> class MatrixBase
/////////// Geometry module ///////////
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ /// \internal helper struct to form the return type of the cross product
+ template<typename OtherDerived> struct cross_product_return_type {
+ typedef typename internal::scalar_product_traits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType Scalar;
+ typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> type;
+ };
+ #endif // EIGEN_PARSED_BY_DOXYGEN
template<typename OtherDerived>
- PlainObject cross(const MatrixBase<OtherDerived>& other) const;
+ typename cross_product_return_type<OtherDerived>::type
+ cross(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived>
PlainObject cross3(const MatrixBase<OtherDerived>& other) const;
PlainObject unitOrthogonal(void) const;
diff --git a/Eigen/src/Geometry/OrthoMethods.h b/Eigen/src/Geometry/OrthoMethods.h
index 64ca52e16..52b469881 100644
--- a/Eigen/src/Geometry/OrthoMethods.h
+++ b/Eigen/src/Geometry/OrthoMethods.h
@@ -35,7 +35,7 @@
*/
template<typename Derived>
template<typename OtherDerived>
-inline typename MatrixBase<Derived>::PlainObject
+inline typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type
MatrixBase<Derived>::cross(const MatrixBase<OtherDerived>& other) const
{
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3)
@@ -45,10 +45,10 @@ MatrixBase<Derived>::cross(const MatrixBase<OtherDerived>& other) const
// optimize such a small temporary very well (even within a complex expression)
const typename internal::nested<Derived,2>::type lhs(derived());
const typename internal::nested<OtherDerived,2>::type rhs(other.derived());
- return typename internal::plain_matrix_type<Derived>::type(
- lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1),
- lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2),
- lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)
+ return typename cross_product_return_type<OtherDerived>::type(
+ internal::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
+ internal::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
+ internal::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0))
);
}
@@ -62,9 +62,9 @@ struct cross3_impl {
run(const VectorLhs& lhs, const VectorRhs& rhs)
{
return typename internal::plain_matrix_type<VectorLhs>::type(
- lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1),
- lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2),
- lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0),
+ internal::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
+ internal::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
+ internal::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
0
);
}
@@ -121,16 +121,16 @@ VectorwiseOp<ExpressionType,Direction>::cross(const MatrixBase<OtherDerived>& ot
if(Direction==Vertical)
{
eigen_assert(CrossReturnType::RowsAtCompileTime==3 && "the matrix must have exactly 3 rows");
- res.row(0) = _expression().row(1) * other.coeff(2) - _expression().row(2) * other.coeff(1);
- res.row(1) = _expression().row(2) * other.coeff(0) - _expression().row(0) * other.coeff(2);
- res.row(2) = _expression().row(0) * other.coeff(1) - _expression().row(1) * other.coeff(0);
+ res.row(0) = (_expression().row(1) * other.coeff(2) - _expression().row(2) * other.coeff(1)).conjugate();
+ res.row(1) = (_expression().row(2) * other.coeff(0) - _expression().row(0) * other.coeff(2)).conjugate();
+ res.row(2) = (_expression().row(0) * other.coeff(1) - _expression().row(1) * other.coeff(0)).conjugate();
}
else
{
eigen_assert(CrossReturnType::ColsAtCompileTime==3 && "the matrix must have exactly 3 columns");
- res.col(0) = _expression().col(1) * other.coeff(2) - _expression().col(2) * other.coeff(1);
- res.col(1) = _expression().col(2) * other.coeff(0) - _expression().col(0) * other.coeff(2);
- res.col(2) = _expression().col(0) * other.coeff(1) - _expression().col(1) * other.coeff(0);
+ res.col(0) = (_expression().col(1) * other.coeff(2) - _expression().col(2) * other.coeff(1)).conjugate();
+ res.col(1) = (_expression().col(2) * other.coeff(0) - _expression().col(0) * other.coeff(2)).conjugate();
+ res.col(2) = (_expression().col(0) * other.coeff(1) - _expression().col(1) * other.coeff(0)).conjugate();
}
return res;
}