26 #ifndef EIGEN_ORTHOMETHODS_H
27 #define EIGEN_ORTHOMETHODS_H
38 template<
typename Derived>
39 template<
typename OtherDerived>
40 inline typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type
48 typename internal::nested<Derived,2>::type lhs(derived());
49 typename internal::nested<OtherDerived,2>::type rhs(other.derived());
50 return typename cross_product_return_type<OtherDerived>::type(
51 internal::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
52 internal::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
53 internal::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0))
59 template<
int Arch,
typename VectorLhs,
typename VectorRhs,
60 typename Scalar =
typename VectorLhs::Scalar,
63 static inline typename internal::plain_matrix_type<VectorLhs>::type
64 run(
const VectorLhs& lhs,
const VectorRhs& rhs)
66 return typename internal::plain_matrix_type<VectorLhs>::type(
67 internal::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
68 internal::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
69 internal::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
86 template<
typename Derived>
87 template<
typename OtherDerived>
88 inline typename MatrixBase<Derived>::PlainObject
94 typedef typename internal::nested<Derived,2>::type DerivedNested;
95 typedef typename internal::nested<OtherDerived,2>::type OtherDerivedNested;
96 const DerivedNested lhs(derived());
97 const OtherDerivedNested rhs(other.derived());
100 typename internal::remove_all<DerivedNested>::type,
101 typename internal::remove_all<OtherDerivedNested>::type>::run(lhs,rhs);
113 template<
typename ExpressionType,
int Direction>
114 template<
typename OtherDerived>
120 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
125 eigen_assert(CrossReturnType::RowsAtCompileTime==3 &&
"the matrix must have exactly 3 rows");
126 res.row(0) = (_expression().row(1) * other.coeff(2) - _expression().
row(2) * other.coeff(1)).
conjugate();
127 res.row(1) = (_expression().row(2) * other.coeff(0) - _expression().
row(0) * other.coeff(2)).
conjugate();
128 res.row(2) = (_expression().row(0) * other.coeff(1) - _expression().
row(1) * other.coeff(0)).
conjugate();
132 eigen_assert(CrossReturnType::ColsAtCompileTime==3 &&
"the matrix must have exactly 3 columns");
133 res.col(0) = (_expression().col(1) * other.coeff(2) - _expression().
col(2) * other.coeff(1)).
conjugate();
134 res.col(1) = (_expression().col(2) * other.coeff(0) - _expression().
col(0) * other.coeff(2)).
conjugate();
135 res.col(2) = (_expression().col(0) * other.coeff(1) - _expression().
col(1) * other.coeff(0)).
conjugate();
142 template<
typename Derived,
int Size = Derived::SizeAtCompileTime>
143 struct unitOrthogonal_selector
145 typedef typename plain_matrix_type<Derived>::type VectorType;
148 typedef typename Derived::Index Index;
150 static inline VectorType run(
const Derived& src)
152 VectorType perp = VectorType::Zero(src.size());
158 RealScalar invnm = RealScalar(1)/(Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm();
159 perp.coeffRef(maxi) = -
conj(src.coeff(sndi)) * invnm;
160 perp.coeffRef(sndi) =
conj(src.coeff(maxi)) * invnm;
166 template<
typename Derived>
167 struct unitOrthogonal_selector<Derived,3>
169 typedef typename plain_matrix_type<Derived>::type VectorType;
172 static inline VectorType run(
const Derived& src)
185 RealScalar invnm = RealScalar(1)/src.template head<2>().norm();
186 perp.coeffRef(0) = -
conj(src.y())*invnm;
187 perp.coeffRef(1) =
conj(src.x())*invnm;
188 perp.coeffRef(2) = 0;
196 RealScalar invnm = RealScalar(1)/src.template tail<2>().norm();
197 perp.coeffRef(0) = 0;
198 perp.coeffRef(1) = -
conj(src.z())*invnm;
199 perp.coeffRef(2) =
conj(src.y())*invnm;
206 template<
typename Derived>
207 struct unitOrthogonal_selector<Derived,2>
209 typedef typename plain_matrix_type<Derived>::type VectorType;
210 static inline VectorType run(
const Derived& src)
211 {
return VectorType(-
conj(src.y()),
conj(src.x())).normalized(); }
223 template<
typename Derived>
224 typename MatrixBase<Derived>::PlainObject
228 return internal::unitOrthogonal_selector<Derived>::run(derived());
233 #endif // EIGEN_ORTHOMETHODS_H