11 #ifndef EIGEN_ORTHOMETHODS_H
12 #define EIGEN_ORTHOMETHODS_H
23 template<
typename Derived>
24 template<
typename OtherDerived>
25 inline typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type
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 numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
37 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
38 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0))
44 template<
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 numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
53 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
54 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
71 template<
typename Derived>
72 template<
typename OtherDerived>
73 inline typename MatrixBase<Derived>::PlainObject
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 DerivedNested lhs(derived());
82 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);
98 template<
typename ExpressionType,
int Direction>
99 template<
typename OtherDerived>
100 const 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();
127 template<
typename Derived,
int Size = Derived::SizeAtCompileTime>
128 struct unitOrthogonal_selector
130 typedef typename plain_matrix_type<Derived>::type VectorType;
131 typedef typename traits<Derived>::Scalar Scalar;
133 typedef typename Derived::Index Index;
135 static inline VectorType run(
const Derived& src)
137 VectorType perp = VectorType::Zero(src.size());
143 RealScalar invnm = RealScalar(1)/(Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm();
144 perp.coeffRef(maxi) = -numext::conj(src.coeff(sndi)) * invnm;
145 perp.coeffRef(sndi) = numext::conj(src.coeff(maxi)) * invnm;
151 template<
typename Derived>
152 struct 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) = -numext::conj(src.y())*invnm;
172 perp.coeffRef(1) = numext::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) = -numext::conj(src.z())*invnm;
184 perp.coeffRef(2) = numext::conj(src.y())*invnm;
191 template<
typename Derived>
192 struct unitOrthogonal_selector<Derived,2>
194 typedef typename plain_matrix_type<Derived>::type VectorType;
195 static inline VectorType run(
const Derived& src)
196 {
return VectorType(-numext::conj(src.y()), numext::conj(src.x())).normalized(); }
208 template<
typename Derived>
209 typename MatrixBase<Derived>::PlainObject
212 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
213 return internal::unitOrthogonal_selector<Derived>::run(derived());
218 #endif // EIGEN_ORTHOMETHODS_H
RowXpr row(Index i)
Definition: DenseBase.h:750
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
Pseudo expression providing partial reduction operations.
Definition: ForwardDeclarations.h:212
ColXpr col(Index i)
Definition: DenseBase.h:733
const unsigned int PacketAccessBit
Definition: Constants.h:81
Definition: Constants.h:209
PlainObject unitOrthogonal(void) const
Definition: OrthoMethods.h:210
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > cwiseAbs() const
Definition: MatrixBase.h:22