11#ifndef EIGEN_ORTHOMETHODS_H
12#define EIGEN_ORTHOMETHODS_H
14#include "./InternalHeaderCheck.h"
29template<
typename Derived>
30template<
typename OtherDerived>
31#ifndef EIGEN_PARSED_BY_DOXYGEN
32EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
33typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type
35typename MatrixBase<Derived>::PlainObject
39 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3)
40 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
44 typename internal::nested_eval<Derived,2>::type lhs(derived());
45 typename internal::nested_eval<OtherDerived,2>::type rhs(other.
derived());
46 return typename cross_product_return_type<OtherDerived>::type(
47 numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
48 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
49 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0))
55template<
int Arch,
typename VectorLhs,
typename VectorRhs,
56 typename Scalar =
typename VectorLhs::Scalar,
57 bool Vectorizable = bool((VectorLhs::Flags&VectorRhs::Flags)&
PacketAccessBit)>
59 EIGEN_DEVICE_FUNC
static inline typename internal::plain_matrix_type<VectorLhs>::type
60 run(
const VectorLhs& lhs,
const VectorRhs& rhs)
62 return typename internal::plain_matrix_type<VectorLhs>::type(
63 numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
64 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
65 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
82template<
typename Derived>
83template<
typename OtherDerived>
84EIGEN_DEVICE_FUNC
inline typename MatrixBase<Derived>::PlainObject
87 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,4)
88 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,4)
90 typedef typename internal::nested_eval<Derived,2>::type DerivedNested;
91 typedef typename internal::nested_eval<OtherDerived,2>::type OtherDerivedNested;
92 DerivedNested lhs(derived());
93 OtherDerivedNested rhs(other.
derived());
95 return internal::cross3_impl<Architecture::Target,
96 typename internal::remove_all<DerivedNested>::type,
97 typename internal::remove_all<OtherDerivedNested>::type>::run(lhs,rhs);
109template<
typename ExpressionType,
int Direction>
110template<
typename OtherDerived>
112const typename VectorwiseOp<ExpressionType,Direction>::CrossReturnType
115 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
116 EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
117 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
119 typename internal::nested_eval<ExpressionType,2>::type mat(_expression());
120 typename internal::nested_eval<OtherDerived,2>::type vec(other.
derived());
122 CrossReturnType res(_expression().rows(),_expression().cols());
125 eigen_assert(CrossReturnType::RowsAtCompileTime==3 &&
"the matrix must have exactly 3 rows");
126 res.row(0) = (mat.row(1) * vec.coeff(2) - mat.row(2) * vec.coeff(1)).conjugate();
127 res.row(1) = (mat.row(2) * vec.coeff(0) - mat.row(0) * vec.coeff(2)).conjugate();
128 res.row(2) = (mat.row(0) * vec.coeff(1) - mat.row(1) * vec.coeff(0)).conjugate();
132 eigen_assert(CrossReturnType::ColsAtCompileTime==3 &&
"the matrix must have exactly 3 columns");
133 res.col(0) = (mat.col(1) * vec.coeff(2) - mat.col(2) * vec.coeff(1)).conjugate();
134 res.col(1) = (mat.col(2) * vec.coeff(0) - mat.col(0) * vec.coeff(2)).conjugate();
135 res.col(2) = (mat.col(0) * vec.coeff(1) - mat.col(1) * vec.coeff(0)).conjugate();
142template<
typename Derived,
int Size = Derived::SizeAtCompileTime>
143struct unitOrthogonal_selector
145 typedef typename plain_matrix_type<Derived>::type VectorType;
146 typedef typename traits<Derived>::Scalar Scalar;
150 static inline VectorType run(
const Derived& src)
152 VectorType perp = VectorType::Zero(src.size());
155 src.cwiseAbs().maxCoeff(&maxi);
158 RealScalar invnm = RealScalar(1)/(
Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm();
159 perp.coeffRef(maxi) = -numext::conj(src.coeff(sndi)) * invnm;
160 perp.coeffRef(sndi) = numext::conj(src.coeff(maxi)) * invnm;
166template<
typename Derived>
167struct unitOrthogonal_selector<Derived,3>
169 typedef typename plain_matrix_type<Derived>::type VectorType;
170 typedef typename traits<Derived>::Scalar Scalar;
171 typedef typename NumTraits<Scalar>::Real RealScalar;
173 static inline VectorType run(
const Derived& src)
183 if((!isMuchSmallerThan(src.x(), src.z()))
184 || (!isMuchSmallerThan(src.y(), src.z())))
186 RealScalar invnm = RealScalar(1)/src.template head<2>().norm();
187 perp.coeffRef(0) = -numext::conj(src.y())*invnm;
188 perp.coeffRef(1) = numext::conj(src.x())*invnm;
189 perp.coeffRef(2) = 0;
197 RealScalar invnm = RealScalar(1)/src.template tail<2>().norm();
198 perp.coeffRef(0) = 0;
199 perp.coeffRef(1) = -numext::conj(src.z())*invnm;
200 perp.coeffRef(2) = numext::conj(src.y())*invnm;
207template<
typename Derived>
208struct unitOrthogonal_selector<Derived,2>
210 typedef typename plain_matrix_type<Derived>::type VectorType;
212 static inline VectorType run(
const Derived& src)
213 {
return VectorType(-numext::conj(src.y()), numext::conj(src.x())).normalized(); }
227template<
typename Derived>
228EIGEN_DEVICE_FUNC
typename MatrixBase<Derived>::PlainObject
231 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
232 return internal::unitOrthogonal_selector<Derived>::run(derived());
Derived & derived()
Definition: EigenBase.h:48
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
PlainObject cross(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h:37
const CrossReturnType cross(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h:113
PlainObject unitOrthogonal(void) const
Definition: OrthoMethods.h:229
PlainObject cross3(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h:85
@ Vertical
Definition: Constants.h:266
const unsigned int PacketAccessBit
Definition: Constants.h:96
Matrix< Type, 2, 1 > Vector2
[c++11]
Definition: Matrix.h:528
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:235