11 #ifndef EIGEN_ORTHOMETHODS_H
12 #define EIGEN_ORTHOMETHODS_H
27 template<
typename Derived>
28 template<
typename OtherDerived>
29 inline typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type
32 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3)
33 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
37 typename internal::nested_eval<Derived,2>::type lhs(derived());
38 typename internal::nested_eval<OtherDerived,2>::type rhs(other.derived());
39 return typename cross_product_return_type<OtherDerived>::type(
40 numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
41 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
42 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0))
48 template<
int Arch,
typename VectorLhs,
typename VectorRhs,
49 typename Scalar =
typename VectorLhs::Scalar,
50 bool Vectorizable = bool((VectorLhs::Flags&VectorRhs::Flags)&
PacketAccessBit)>
52 static inline typename internal::plain_matrix_type<VectorLhs>::type
53 run(
const VectorLhs& lhs,
const VectorRhs& rhs)
55 return typename internal::plain_matrix_type<VectorLhs>::type(
56 numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
57 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
58 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
75 template<
typename Derived>
76 template<
typename OtherDerived>
77 inline typename MatrixBase<Derived>::PlainObject
80 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,4)
81 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,4)
83 typedef typename internal::nested_eval<Derived,2>::type DerivedNested;
84 typedef typename internal::nested_eval<OtherDerived,2>::type OtherDerivedNested;
85 DerivedNested lhs(derived());
86 OtherDerivedNested rhs(other.derived());
88 return internal::cross3_impl<Architecture::Target,
89 typename internal::remove_all<DerivedNested>::type,
90 typename internal::remove_all<OtherDerivedNested>::type>::run(lhs,rhs);
102 template<
typename ExpressionType,
int Direction>
103 template<
typename OtherDerived>
104 const typename VectorwiseOp<ExpressionType,Direction>::CrossReturnType
107 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
108 EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
109 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
111 typename internal::nested_eval<ExpressionType,2>::type mat(_expression());
112 typename internal::nested_eval<OtherDerived,2>::type vec(other.derived());
114 CrossReturnType res(_expression().rows(),_expression().cols());
117 eigen_assert(CrossReturnType::RowsAtCompileTime==3 &&
"the matrix must have exactly 3 rows");
118 res.row(0) = (mat.row(1) * vec.coeff(2) - mat.row(2) * vec.coeff(1)).conjugate();
119 res.row(1) = (mat.row(2) * vec.coeff(0) - mat.row(0) * vec.coeff(2)).conjugate();
120 res.row(2) = (mat.row(0) * vec.coeff(1) - mat.row(1) * vec.coeff(0)).conjugate();
124 eigen_assert(CrossReturnType::ColsAtCompileTime==3 &&
"the matrix must have exactly 3 columns");
125 res.col(0) = (mat.col(1) * vec.coeff(2) - mat.col(2) * vec.coeff(1)).conjugate();
126 res.col(1) = (mat.col(2) * vec.coeff(0) - mat.col(0) * vec.coeff(2)).conjugate();
127 res.col(2) = (mat.col(0) * vec.coeff(1) - mat.col(1) * vec.coeff(0)).conjugate();
134 template<
typename Derived,
int Size = Derived::SizeAtCompileTime>
135 struct unitOrthogonal_selector
137 typedef typename plain_matrix_type<Derived>::type VectorType;
138 typedef typename traits<Derived>::Scalar Scalar;
142 static inline VectorType run(
const Derived& src)
144 VectorType perp = VectorType::Zero(src.size());
147 src.cwiseAbs().maxCoeff(&maxi);
150 RealScalar invnm = RealScalar(1)/(Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm();
151 perp.coeffRef(maxi) = -numext::conj(src.coeff(sndi)) * invnm;
152 perp.coeffRef(sndi) = numext::conj(src.coeff(maxi)) * invnm;
158 template<
typename Derived>
159 struct unitOrthogonal_selector<Derived,3>
161 typedef typename plain_matrix_type<Derived>::type VectorType;
162 typedef typename traits<Derived>::Scalar Scalar;
163 typedef typename NumTraits<Scalar>::Real RealScalar;
165 static inline VectorType run(
const Derived& src)
175 if((!isMuchSmallerThan(src.x(), src.z()))
176 || (!isMuchSmallerThan(src.y(), src.z())))
178 RealScalar invnm = RealScalar(1)/src.template head<2>().norm();
179 perp.coeffRef(0) = -numext::conj(src.y())*invnm;
180 perp.coeffRef(1) = numext::conj(src.x())*invnm;
181 perp.coeffRef(2) = 0;
189 RealScalar invnm = RealScalar(1)/src.template tail<2>().norm();
190 perp.coeffRef(0) = 0;
191 perp.coeffRef(1) = -numext::conj(src.z())*invnm;
192 perp.coeffRef(2) = numext::conj(src.y())*invnm;
199 template<
typename Derived>
200 struct unitOrthogonal_selector<Derived,2>
202 typedef typename plain_matrix_type<Derived>::type VectorType;
204 static inline VectorType run(
const Derived& src)
205 {
return VectorType(-numext::conj(src.y()), numext::conj(src.x())).normalized(); }
217 template<
typename Derived>
218 typename MatrixBase<Derived>::PlainObject
221 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
222 return internal::unitOrthogonal_selector<Derived>::run(derived());
227 #endif // EIGEN_ORTHOMETHODS_H
PlainObject unitOrthogonal(void) const
Definition: OrthoMethods.h:219
const CrossReturnType cross(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h:105
Definition: Constants.h:257
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:107
const unsigned int PacketAccessBit
Definition: Constants.h:80
PlainObject cross3(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h:78
Definition: Eigen_Colamd.h:54
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48