From 84b3da227cda0b66a2c8ebaa99aeddedf8858b02 Mon Sep 17 00:00:00 2001 From: kritz Date: Thu, 22 Aug 2019 15:05:14 +0200 Subject: [PATCH] Canonical Quaternion with tests (#81) --- matrix/Quaternion.hpp | 24 ++++++++++++++++++++++++ test/attitude.cpp | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/matrix/Quaternion.hpp b/matrix/Quaternion.hpp index 29e711dc46..f543a1b929 100644 --- a/matrix/Quaternion.hpp +++ b/matrix/Quaternion.hpp @@ -352,6 +352,30 @@ public: -q(3)/normSq); } + /** + * Bring quaternion to canonical form + */ + void canonicalize() + { + *this = this->canonical(); + } + + + /** + * Return canonical form of the quaternion + * + * @return quaternion in canonical from + */ + Quaternion canonical() const + { + const Quaternion &q = *this; + if(q(0)