Add Quaternion to rotation matrix

This commit is contained in:
Milo Priegnitz 2024-06-22 15:30:31 +02:00 committed by dario
parent 86cd951d5e
commit 1393ade57b
2 changed files with 20 additions and 5 deletions

View File

@ -8,6 +8,7 @@
#ifndef STA_PEAK_QUATERNION_HPP
#define STA_PEAK_QUATERNION_HPP
#include <sta/math/linalg/matrix.hpp>
namespace sta
{
namespace math {
@ -55,11 +56,8 @@ namespace sta
*/
float norm();
/**
* @brief
*
* @return Quaternion
*/
matrix toRotationMatrix();
Quaternion normalized();
Quaternion conjugate();

View File

@ -54,6 +54,23 @@ namespace sta
return Quaternion(qw, qx, qy, qz).normalized();
}
matrix Quaternion::toRotationMatrix(){
matrix R = matrix(3, 3);
R.set(0, 0, 2 *(w*w + x*x) - 1);
R.set(0, 1, 2 *(x*y - w*z));
R.set(0, 2, 2 *(x*z + w*y));
R.set(1, 0, 2 *(x*y + w*z));
R.set(1, 1, 2 *(w*w + y*y) - 1);
R.set(1, 2, 2 *(y*z - w*x));
R.set(2, 0, 2 *(x*z - w*y));
R.set(2, 1, 2 *(y*z + w*x));
R.set(2, 2, 2 *(w*w + z*z) - 1);
return R;
}
Quaternion Quaternion::unit()
{
return Quaternion();