/** * @file Euler.hpp * * Euler angle tait-bryan body 3-2-1 * * @author James Goppert */ #pragma once #include "math.hpp" namespace matrix { template class Dcm; template class Quaternion; template class Euler : public Vector { public: virtual ~Euler() {}; Euler() : Vector() { } Euler(const Vector & other) : Vector(other) { } Euler(const Matrix & other) : Vector(other) { } Euler(Type phi_, Type theta_, Type psi_) : Vector() { phi() = phi_; theta() = theta_; psi() = psi_; } Euler(const Dcm & dcm) : Vector() { theta() = (Type)asin(-dcm(2,0)); if (fabs(theta() - (Type)M_PI_2) < 1.0e-3) { phi() = (Type)0.0; psi() = (Type)atan2(dcm(1,2) - dcm(0,1), dcm(0,2) + dcm(1,1)) + theta(); } else if (fabs(theta() + (Type)M_PI_2) < (Type)1.0e-3) { phi() = (Type)0.0; psi() = (Type)atan2(dcm(1,2) - dcm(0,1), dcm(0,2) + dcm(1,1)) - theta(); } else { phi() = (Type)atan2(dcm(2,1), dcm(2,2)); psi() = (Type)atan2(dcm(1,0), dcm(0,0)); } } Euler(const Quaternion & q) : Vector() { *this = Euler(Dcm(q)); } inline Type phi() const { return (*this)(0); } inline Type theta() const { return (*this)(1); } inline Type psi() const { return (*this)(2); } inline Type & phi() { return (*this)(0); } inline Type & theta() { return (*this)(1); } inline Type & psi() { return (*this)(2); } }; typedef Euler Eulerf; }; // namespace matrix /* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */