diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-12 17:07:38 +0200 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@CROOKED-SCHEMER> | 2016-08-12 17:11:41 +0200 | 
| commit | c63c29d0e09a939c45f2a209ec7c6f0998138589 (patch) | |
| tree | 803a7bf2191b2955e4e0de68a1180e863934f983 /opentrack-logic | |
| parent | 91755ca9ea20735568b4d5cf40a0a7ee7d5d2b7a (diff) | |
logic/simple-mat: add untested tait-bryan rotation composition function
Diffstat (limited to 'opentrack-logic')
| -rw-r--r-- | opentrack-logic/simple-mat.cpp | 42 | ||||
| -rw-r--r-- | opentrack-logic/simple-mat.hpp | 8 | 
2 files changed, 47 insertions, 3 deletions
| diff --git a/opentrack-logic/simple-mat.cpp b/opentrack-logic/simple-mat.cpp index 1aaeb296..8c97f192 100644 --- a/opentrack-logic/simple-mat.cpp +++ b/opentrack-logic/simple-mat.cpp @@ -4,7 +4,7 @@  namespace euler { -euler_t OPENTRACK_LOGIC_EXPORT rmat_to_euler(const dmat<3, 3>& R) +euler_t OPENTRACK_LOGIC_EXPORT rmat_to_euler(const rmat& R)  {      using std::atan2;      using std::sqrt; @@ -54,4 +54,44 @@ rmat OPENTRACK_LOGIC_EXPORT euler_to_rmat(const euler_t& input)                  );  } +// https://en.wikipedia.org/wiki/Davenport_chained_rotations#Tait.E2.80.93Bryan_chained_rotations +void OPENTRACK_LOGIC_EXPORT tait_bryan_to_matrices(const euler_t& input, +                                                   rmat& r_roll, +                                                   rmat& r_pitch, +                                                   rmat& r_yaw) +{ +    using std::cos; +    using std::sin; + +    { +        const double phi = -input(2); +        const double sin_phi = sin(phi); +        const double cos_phi = cos(phi); + +        r_roll = rmat(1, 0, 0, +                      0, cos_phi, -sin_phi, +                      0, sin_phi, cos_phi); +    } + +    { +        const double theta = -input(1); +        const double sin_theta = sin(theta); +        const double cos_theta = cos(theta); + +        r_pitch = rmat(cos_theta, 0, -sin_theta, +                       0, 1, 0, +                       sin_theta, 0, cos_theta); +    } + +    { +        const double psi = -input(0); +        const double sin_psi = sin(psi); +        const double cos_psi = cos(psi); + +        r_yaw = rmat(cos_psi, -sin_psi, 0, +                     sin_psi, cos_psi, 0, +                     0, 0, 1); +    } +} +  } // end ns euler diff --git a/opentrack-logic/simple-mat.hpp b/opentrack-logic/simple-mat.hpp index 09de6004..514e845f 100644 --- a/opentrack-logic/simple-mat.hpp +++ b/opentrack-logic/simple-mat.hpp @@ -269,7 +269,11 @@ using euler_t = dmat<3, 1>;  rmat OPENTRACK_LOGIC_EXPORT euler_to_rmat(const euler_t& input); -// http://stackoverflow.com/a/18436193 -euler_t OPENTRACK_LOGIC_EXPORT rmat_to_euler(const dmat<3, 3>& R); +euler_t OPENTRACK_LOGIC_EXPORT rmat_to_euler(const rmat& R); + +void OPENTRACK_LOGIC_EXPORT tait_bryan_to_matrices(const euler_t& input, +                                                   rmat& r_roll, +                                                   rmat& r_pitch, +                                                   rmat& r_yaw);  } // end ns euler | 
