diff options
author | Gael Guennebaud <g.gael@free.fr> | 2009-02-25 09:23:09 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2009-02-25 09:23:09 +0000 |
commit | 91af389a9a39deac44a663a1467654ba7874bc93 (patch) | |
tree | 584b4cf8c8bb3dc6937b2459c94a307e9af8e7f8 /Eigen/src/Geometry | |
parent | 2d6d14a3d3c7f2e18357f89f815ad526a4e32ce5 (diff) |
fix unitOrthogonal() for size > 3
Diffstat (limited to 'Eigen/src/Geometry')
-rw-r--r-- | Eigen/src/Geometry/OrthoMethods.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/Eigen/src/Geometry/OrthoMethods.h b/Eigen/src/Geometry/OrthoMethods.h index e22df114a..4676474db 100644 --- a/Eigen/src/Geometry/OrthoMethods.h +++ b/Eigen/src/Geometry/OrthoMethods.h @@ -92,9 +92,32 @@ struct ei_unitOrthogonal_selector typedef typename ei_plain_matrix_type<Derived>::type VectorType; typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename NumTraits<Scalar>::Real RealScalar; + typedef Matrix<Scalar,2,1> Vector2; inline static VectorType run(const Derived& src) { - VectorType perp(src.size()); + VectorType perp = VectorType::Zero(src.size()); + int maxi = 0; + int sndi = 0; + src.cwise().abs().maxCoeff(&maxi); + if (maxi==0) + sndi = 1; + RealScalar invnm = RealScalar(1)/Vector2(src.coeff(sndi),src.coeff(maxi)).norm(); + perp.coeffRef(maxi) = -ei_conj(src.coeff(sndi)) * invnm; + perp.coeffRef(sndi) = ei_conj(src.coeff(maxi)) * invnm; + + return perp; + } +}; + +template<typename Derived> +struct ei_unitOrthogonal_selector<Derived,3> +{ + typedef typename ei_plain_matrix_type<Derived>::type VectorType; + typedef typename ei_traits<Derived>::Scalar Scalar; + typedef typename NumTraits<Scalar>::Real RealScalar; + inline static VectorType run(const Derived& src) + { + VectorType perp; /* Let us compute the crossed product of *this with a vector * that is not too close to being colinear to *this. */ @@ -121,9 +144,6 @@ struct ei_unitOrthogonal_selector perp.coeffRef(1) = -ei_conj(src.z())*invnm; perp.coeffRef(2) = ei_conj(src.y())*invnm; } - if( (Derived::SizeAtCompileTime!=Dynamic && Derived::SizeAtCompileTime>3) - || (Derived::SizeAtCompileTime==Dynamic && src.size()>3) ) - perp.end(src.size()-3).setZero(); return perp; } |