From 21d47424c6050bb94da5de3f7580a8df66b6fcc7 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Sat, 31 Mar 2018 16:59:03 -0400 Subject: [PATCH] Quaternion mark const helpers const --- matrix/Quaternion.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/matrix/Quaternion.hpp b/matrix/Quaternion.hpp index 4961fab..87bea23 100644 --- a/matrix/Quaternion.hpp +++ b/matrix/Quaternion.hpp @@ -346,9 +346,9 @@ class Quaternion : public Vector * * @return inverted quaternion */ - Quaternion inversed() + Quaternion inversed() const { - Quaternion &q = *this; + const Quaternion &q = *this; Type normSq = q.dot(q); return Quaternion( q(0)/normSq, @@ -393,7 +393,8 @@ class Quaternion : public Vector * @param vec vector to rotate in frame 2 (typically reference frame) * @return rotated vector in frame 1 (typically body frame) */ - Vector3f conjugate_inversed(const Vector3f &vec) { + Vector3f conjugate_inversed(const Vector3f &vec) const + { Quaternion q = *this; Quaternion v(0, vec(0), vec(1), vec(2)); Quaternion res = q.inversed()*v*q; @@ -459,9 +460,9 @@ class Quaternion : public Vector * * @return vector, direction representing rotation axis and norm representing angle */ - Vector to_axis_angle() + Vector to_axis_angle() const { - Quaternion &q = *this; + const Quaternion &q = *this; Type axis_magnitude = Type(sqrt(q(1) * q(1) + q(2) * q(2) + q(3) * q(3))); Vector vec; vec(0) = q(1); @@ -479,9 +480,9 @@ class Quaternion : public Vector /** * Imaginary components of quaternion */ - Vector3 imag() + Vector3 imag() const { - Quaternion &q = *this; + const Quaternion &q = *this; return Vector3(q(1), q(2), q(3)); } @@ -492,9 +493,9 @@ class Quaternion : public Vector * == last column of the equivalent rotation matrix * but calculated more efficiently than a full conversion */ - Vector3 dcm_z() + Vector3 dcm_z() const { - Quaternion &q = *this; + const Quaternion &q = *this; Vector3 R_z; const Type a = q(0); const Type b = q(1);