11#ifndef EIGEN_ORTHOMETHODS_H
12#define EIGEN_ORTHOMETHODS_H
23template<
typename Derived>
24template<
typename OtherDerived>
26MatrixBase<Derived>::cross(
const MatrixBase<OtherDerived>& other)
const
28 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3)
29 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
33 typename internal::nested<Derived,2>::type lhs(derived());
34 typename internal::nested<OtherDerived,2>::type rhs(other.derived());
35 return typename cross_product_return_type<OtherDerived>::type(
36 internal::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
37 internal::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
38 internal::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0))
44template<
int Arch,
typename VectorLhs,
typename VectorRhs,
45 typename Scalar =
typename VectorLhs::Scalar,
46 bool Vectorizable = bool((VectorLhs::Flags&VectorRhs::Flags)&
PacketAccessBit)>
48 static inline typename internal::plain_matrix_type<VectorLhs>::type
49 run(
const VectorLhs& lhs,
const VectorRhs& rhs)
51 return typename internal::plain_matrix_type<VectorLhs>::type(
52 internal::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
53 internal::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
54 internal::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
71template<
typename Derived>
72template<
typename OtherDerived>
76 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,4)
77 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,4)
79 typedef typename internal::nested<Derived,2>::type DerivedNested;
80 typedef typename internal::nested<OtherDerived,2>::type OtherDerivedNested;
81 const DerivedNested lhs(derived());
82 const OtherDerivedNested rhs(other.derived());
84 return internal::cross3_impl<Architecture::Target,
85 typename internal::remove_all<DerivedNested>::type,
86 typename internal::remove_all<OtherDerivedNested>::type>::run(lhs,rhs);
98template<
typename ExpressionType,
int Direction>
99template<
typename OtherDerived>
100const typename VectorwiseOp<ExpressionType,Direction>::CrossReturnType
103 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
104 EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
105 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
107 CrossReturnType res(_expression().rows(),_expression().cols());
110 eigen_assert(CrossReturnType::RowsAtCompileTime==3 &&
"the matrix must have exactly 3 rows");
111 res.row(0) = (_expression().row(1) * other.coeff(2) - _expression().
row(2) * other.coeff(1)).conjugate();
112 res.row(1) = (_expression().row(2) * other.coeff(0) - _expression().
row(0) * other.coeff(2)).conjugate();
113 res.row(2) = (_expression().row(0) * other.coeff(1) - _expression().
row(1) * other.coeff(0)).conjugate();
117 eigen_assert(CrossReturnType::ColsAtCompileTime==3 &&
"the matrix must have exactly 3 columns");
118 res.col(0) = (_expression().col(1) * other.coeff(2) - _expression().
col(2) * other.coeff(1)).conjugate();
119 res.col(1) = (_expression().col(2) * other.coeff(0) - _expression().
col(0) * other.coeff(2)).conjugate();
120 res.col(2) = (_expression().col(0) * other.coeff(1) - _expression().
col(1) * other.coeff(0)).conjugate();
127template<
typename Derived,
int Size = Derived::SizeAtCompileTime>
128struct unitOrthogonal_selector
130 typedef typename plain_matrix_type<Derived>::type VectorType;
131 typedef typename traits<Derived>::Scalar Scalar;
132 typedef typename NumTraits<Scalar>::Real RealScalar;
133 typedef typename Derived::Index Index;
135 static inline VectorType run(
const Derived& src)
137 VectorType perp = VectorType::Zero(src.size());
140 src.cwiseAbs().maxCoeff(&maxi);
143 RealScalar invnm = RealScalar(1)/(Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm();
144 perp.coeffRef(maxi) = -conj(src.coeff(sndi)) * invnm;
145 perp.coeffRef(sndi) = conj(src.coeff(maxi)) * invnm;
151template<
typename Derived>
152struct unitOrthogonal_selector<Derived,3>
154 typedef typename plain_matrix_type<Derived>::type VectorType;
155 typedef typename traits<Derived>::Scalar Scalar;
156 typedef typename NumTraits<Scalar>::Real RealScalar;
157 static inline VectorType run(
const Derived& src)
167 if((!isMuchSmallerThan(src.x(), src.z()))
168 || (!isMuchSmallerThan(src.y(), src.z())))
170 RealScalar invnm = RealScalar(1)/src.template head<2>().norm();
171 perp.coeffRef(0) = -conj(src.y())*invnm;
172 perp.coeffRef(1) = conj(src.x())*invnm;
173 perp.coeffRef(2) = 0;
181 RealScalar invnm = RealScalar(1)/src.template tail<2>().norm();
182 perp.coeffRef(0) = 0;
183 perp.coeffRef(1) = -conj(src.z())*invnm;
184 perp.coeffRef(2) = conj(src.y())*invnm;
191template<
typename Derived>
192struct unitOrthogonal_selector<Derived,2>
194 typedef typename plain_matrix_type<Derived>::type VectorType;
195 static inline VectorType run(
const Derived& src)
196 {
return VectorType(-conj(src.y()), conj(src.x())).normalized(); }
208template<
typename Derived>
212 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
213 return internal::unitOrthogonal_selector<Derived>::run(derived());
ColXpr col(Index i)
Definition DenseBase.h:553
RowXpr row(Index i)
Definition DenseBase.h:570
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
PlainObject unitOrthogonal(void) const
Definition OrthoMethods.h:210
Matrix< typename internal::traits< Derived >::Scalar, internal::traits< Derived >::RowsAtCompileTime, internal::traits< Derived >::ColsAtCompileTime, AutoAlign|(internal::traits< Derived >::Flags &RowMajorBit ? RowMajor :ColMajor), internal::traits< Derived >::MaxRowsAtCompileTime, internal::traits< Derived >::MaxColsAtCompileTime > PlainObject
The plain matrix type corresponding to this expression.
Definition MatrixBase.h:115
PlainObject cross3(const MatrixBase< OtherDerived > &other) const
Definition OrthoMethods.h:74
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:129
const CrossReturnType cross(const MatrixBase< OtherDerived > &other) const
Definition OrthoMethods.h:101
@ Vertical
Definition Constants.h:204
const unsigned int PacketAccessBit
Definition Constants.h:76