12#ifndef EIGEN_ORTHOMETHODS_H
13#define EIGEN_ORTHOMETHODS_H
16#include "./InternalHeaderCheck.h"
23template <
typename Derived,
typename OtherDerived,
int Size>
25 using Scalar =
typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,
26 typename internal::traits<OtherDerived>::Scalar>::ReturnType;
29 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE return_type run(
const MatrixBase<Derived>& first,
30 const MatrixBase<OtherDerived>& second) {
31 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3)
32 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived, 3)
36 typename internal::nested_eval<Derived, 2>::type lhs(first.derived());
37 typename internal::nested_eval<OtherDerived, 2>::type rhs(second.derived());
38 return return_type(numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
39 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
40 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)));
45template <typename Derived, typename OtherDerived>
46struct cross_impl<Derived, OtherDerived, 2> {
47 using Scalar =
typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,
48 typename internal::traits<OtherDerived>::Scalar>::ReturnType;
49 using return_type = Scalar;
51 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE return_type run(
const MatrixBase<Derived>& first,
52 const MatrixBase<OtherDerived>& second) {
53 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 2)
54 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived, 2)
55 typename internal::nested_eval<Derived, 2>::type lhs(first.derived());
56 typename internal::nested_eval<OtherDerived, 2>::type rhs(second.derived());
57 return numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0));
89template <typename Derived>
90template <typename OtherDerived>
91EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::cross_impl<Derived, OtherDerived>::return_type
92MatrixBase<Derived>::
cross(const MatrixBase<OtherDerived>& other)
const {
93 return internal::cross_impl<Derived, OtherDerived>::run(*
this, other);
98template <
int Arch,
typename VectorLhs,
typename VectorRhs,
typename Scalar =
typename VectorLhs::Scalar,
100 bool((
int(evaluator<VectorLhs>::Flags) &
int(evaluator<VectorRhs>::Flags)) &
PacketAccessBit)>
102 EIGEN_DEVICE_FUNC
static inline typename internal::plain_matrix_type<VectorLhs>::type run(
const VectorLhs& lhs,
103 const VectorRhs& rhs) {
104 return typename internal::plain_matrix_type<VectorLhs>::type(
105 numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
106 numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
107 numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)), 0);
122template <
typename Derived>
123template <
typename OtherDerived>
125 const MatrixBase<OtherDerived>& other)
const {
126 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 4)
127 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived, 4)
129 using DerivedNested =
typename internal::nested_eval<Derived, 2>::type;
130 using OtherDerivedNested =
typename internal::nested_eval<OtherDerived, 2>::type;
131 DerivedNested lhs(derived());
132 OtherDerivedNested rhs(other.derived());
134 return internal::cross3_impl<Architecture::Target, internal::remove_all_t<DerivedNested>,
135 internal::remove_all_t<OtherDerivedNested>>::run(lhs, rhs);
147template <
typename ExpressionType,
int Direction>
148template <
typename OtherDerived>
149EIGEN_DEVICE_FUNC
const typename VectorwiseOp<ExpressionType, Direction>::CrossReturnType
151 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived, 3)
153 (std::is_same<Scalar, typename OtherDerived::Scalar>::value),
154 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
156 typename internal::nested_eval<ExpressionType, 2>::type mat(_expression());
157 typename internal::nested_eval<OtherDerived, 2>::type vec(other.derived());
159 CrossReturnType res(_expression().rows(), _expression().cols());
160 EIGEN_IF_CONSTEXPR (Direction ==
Vertical) {
161 eigen_assert(CrossReturnType::RowsAtCompileTime == 3 &&
"the matrix must have exactly 3 rows");
162 res.row(0) = (mat.row(1) * vec.coeff(2) - mat.row(2) * vec.coeff(1)).conjugate();
163 res.row(1) = (mat.row(2) * vec.coeff(0) - mat.row(0) * vec.coeff(2)).conjugate();
164 res.row(2) = (mat.row(0) * vec.coeff(1) - mat.row(1) * vec.coeff(0)).conjugate();
166 eigen_assert(CrossReturnType::ColsAtCompileTime == 3 &&
"the matrix must have exactly 3 columns");
167 res.col(0) = (mat.col(1) * vec.coeff(2) - mat.col(2) * vec.coeff(1)).conjugate();
168 res.col(1) = (mat.col(2) * vec.coeff(0) - mat.col(0) * vec.coeff(2)).conjugate();
169 res.col(2) = (mat.col(0) * vec.coeff(1) - mat.col(1) * vec.coeff(0)).conjugate();
176template <
typename Derived,
int Size = Derived::SizeAtCompileTime>
177struct unitOrthogonal_selector {
178 using VectorType =
typename plain_matrix_type<Derived>::type;
179 using Scalar =
typename traits<Derived>::Scalar;
180 using RealScalar =
typename NumTraits<Scalar>::Real;
182 EIGEN_DEVICE_FUNC
static inline VectorType run(
const Derived& src) {
183 VectorType perp = VectorType::Zero(src.size());
186 src.cwiseAbs().maxCoeff(&maxi);
187 if (maxi == 0) sndi = 1;
188 RealScalar invnm = RealScalar(1) / (
Vector2() << src.coeff(sndi), src.coeff(maxi)).finished().norm();
189 perp.coeffRef(maxi) = -numext::conj(src.coeff(sndi)) * invnm;
190 perp.coeffRef(sndi) = numext::conj(src.coeff(maxi)) * invnm;
196template <
typename Derived>
197struct unitOrthogonal_selector<Derived, 3> {
198 using VectorType =
typename plain_matrix_type<Derived>::type;
199 using Scalar =
typename traits<Derived>::Scalar;
200 using RealScalar =
typename NumTraits<Scalar>::Real;
201 EIGEN_DEVICE_FUNC
static inline VectorType run(
const Derived& src) {
210 if ((!isMuchSmallerThan(src.x(), src.z())) || (!isMuchSmallerThan(src.y(), src.z()))) {
211 RealScalar invnm = RealScalar(1) / src.template head<2>().norm();
212 perp.coeffRef(0) = -numext::conj(src.y()) * invnm;
213 perp.coeffRef(1) = numext::conj(src.x()) * invnm;
214 perp.coeffRef(2) = 0;
221 RealScalar invnm = RealScalar(1) / src.template tail<2>().norm();
222 perp.coeffRef(0) = 0;
223 perp.coeffRef(1) = -numext::conj(src.z()) * invnm;
224 perp.coeffRef(2) = numext::conj(src.y()) * invnm;
231template <
typename Derived>
232struct unitOrthogonal_selector<Derived, 2> {
233 using VectorType =
typename plain_matrix_type<Derived>::type;
234 EIGEN_DEVICE_FUNC
static inline VectorType run(
const Derived& src) {
235 return VectorType(-numext::conj(src.y()), numext::conj(src.x())).normalized();
252template <
typename Derived>
254 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
255 return internal::unitOrthogonal_selector<Derived>::run(derived());
@ ColsAtCompileTime
Definition DenseBase.h:103
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
const CrossReturnType cross(const MatrixBase< OtherDerived > &other) const
Definition OrthoMethods.h:150
PlainObject unitOrthogonal(void) const
Definition OrthoMethods.h:253
PlainObject cross3(const MatrixBase< OtherDerived > &other) const
Definition OrthoMethods.h:124
internal::cross_impl< Derived, OtherDerived >::return_type cross(const MatrixBase< OtherDerived > &other) const
Definition OrthoMethods.h:92
@ Vertical
Definition Constants.h:267
constexpr unsigned int PacketAccessBit
Definition Constants.h:98
Matrix< Type, 2, 1 > Vector2
2×1 vector of type Type.
Definition Matrix.h:521