11 #ifndef EIGEN_ORTHOMETHODS_H 12 #define EIGEN_ORTHOMETHODS_H 27 template<
typename Derived>
28 template<
typename OtherDerived>
29 #ifndef EIGEN_PARSED_BY_DOXYGEN 30 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
31 typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type
33 typename MatrixBase<Derived>::PlainObject
37 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3)
38 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
42 typename internal::nested_eval<Derived,2>::type lhs(derived());
43 typename internal::nested_eval<OtherDerived,2>::type rhs(other.
derived());
44 return typename cross_product_return_type<OtherDerived>::type(
45 numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
46 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
47 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0))
53 template<
int Arch,
typename VectorLhs,
typename VectorRhs,
54 typename Scalar =
typename VectorLhs::Scalar,
55 bool Vectorizable = bool((VectorLhs::Flags&VectorRhs::Flags)&
PacketAccessBit)>
57 EIGEN_DEVICE_FUNC
static inline typename internal::plain_matrix_type<VectorLhs>::type
58 run(
const VectorLhs& lhs,
const VectorRhs& rhs)
60 return typename internal::plain_matrix_type<VectorLhs>::type(
61 numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
62 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
63 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
80 template<
typename Derived>
81 template<
typename OtherDerived>
82 EIGEN_DEVICE_FUNC
inline typename MatrixBase<Derived>::PlainObject
85 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,4)
86 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,4)
88 typedef typename internal::nested_eval<Derived,2>::type DerivedNested;
89 typedef typename internal::nested_eval<OtherDerived,2>::type OtherDerivedNested;
90 DerivedNested lhs(derived());
91 OtherDerivedNested rhs(other.
derived());
93 return internal::cross3_impl<Architecture::Target,
94 typename internal::remove_all<DerivedNested>::type,
95 typename internal::remove_all<OtherDerivedNested>::type>::run(lhs,rhs);
107 template<
typename ExpressionType,
int Direction>
108 template<
typename OtherDerived>
110 const typename VectorwiseOp<ExpressionType,Direction>::CrossReturnType
113 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
114 EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
115 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
117 typename internal::nested_eval<ExpressionType,2>::type mat(_expression());
118 typename internal::nested_eval<OtherDerived,2>::type vec(other.
derived());
120 CrossReturnType res(_expression().rows(),_expression().cols());
123 eigen_assert(CrossReturnType::RowsAtCompileTime==3 &&
"the matrix must have exactly 3 rows");
124 res.row(0) = (mat.row(1) * vec.coeff(2) - mat.row(2) * vec.coeff(1)).conjugate();
125 res.row(1) = (mat.row(2) * vec.coeff(0) - mat.row(0) * vec.coeff(2)).conjugate();
126 res.row(2) = (mat.row(0) * vec.coeff(1) - mat.row(1) * vec.coeff(0)).conjugate();
130 eigen_assert(CrossReturnType::ColsAtCompileTime==3 &&
"the matrix must have exactly 3 columns");
131 res.col(0) = (mat.col(1) * vec.coeff(2) - mat.col(2) * vec.coeff(1)).conjugate();
132 res.col(1) = (mat.col(2) * vec.coeff(0) - mat.col(0) * vec.coeff(2)).conjugate();
133 res.col(2) = (mat.col(0) * vec.coeff(1) - mat.col(1) * vec.coeff(0)).conjugate();
140 template<
typename Derived,
int Size = Derived::SizeAtCompileTime>
141 struct unitOrthogonal_selector
143 typedef typename plain_matrix_type<Derived>::type VectorType;
144 typedef typename traits<Derived>::Scalar Scalar;
148 static inline VectorType run(
const Derived& src)
150 VectorType perp = VectorType::Zero(src.size());
153 src.cwiseAbs().maxCoeff(&maxi);
156 RealScalar invnm = RealScalar(1)/(
Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm();
157 perp.coeffRef(maxi) = -numext::conj(src.coeff(sndi)) * invnm;
158 perp.coeffRef(sndi) = numext::conj(src.coeff(maxi)) * invnm;
164 template<
typename Derived>
165 struct unitOrthogonal_selector<Derived,3>
167 typedef typename plain_matrix_type<Derived>::type VectorType;
168 typedef typename traits<Derived>::Scalar Scalar;
171 static inline VectorType run(
const Derived& src)
181 if((!isMuchSmallerThan(src.x(), src.z()))
182 || (!isMuchSmallerThan(src.y(), src.z())))
184 RealScalar invnm = RealScalar(1)/src.template head<2>().norm();
185 perp.coeffRef(0) = -numext::conj(src.y())*invnm;
186 perp.coeffRef(1) = numext::conj(src.x())*invnm;
187 perp.coeffRef(2) = 0;
195 RealScalar invnm = RealScalar(1)/src.template tail<2>().norm();
196 perp.coeffRef(0) = 0;
197 perp.coeffRef(1) = -numext::conj(src.z())*invnm;
198 perp.coeffRef(2) = numext::conj(src.y())*invnm;
205 template<
typename Derived>
206 struct unitOrthogonal_selector<Derived,2>
208 typedef typename plain_matrix_type<Derived>::type VectorType;
210 static inline VectorType run(
const Derived& src)
211 {
return VectorType(-numext::conj(src.y()), numext::conj(src.x())).normalized(); }
225 template<
typename Derived>
226 EIGEN_DEVICE_FUNC
typename MatrixBase<Derived>::PlainObject
229 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
230 return internal::unitOrthogonal_selector<Derived>::run(derived());
235 #endif // EIGEN_ORTHOMETHODS_H internal::traits< Solve< Decomposition, RhsType > >::Scalar Scalar
Definition: DenseBase.h:66
Definition: Constants.h:264
const CrossReturnType cross(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h:111
Eigen::Index Index
Definition: VectorwiseOp.h:192
Namespace containing all symbols from the Eigen library.
Definition: Core:141
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
Derived & derived()
Definition: EigenBase.h:46
const unsigned int PacketAccessBit
Definition: Constants.h:94
PlainObject cross3(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h:83
PlainObject unitOrthogonal(void) const
Definition: OrthoMethods.h:227
PlainObject cross(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h:35
Definition: Eigen_Colamd.h:50
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
Matrix< Type, 2, 1 > Vector2
[c++11]
Definition: Matrix.h:540