mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-peak.git
synced 2025-06-11 18:35:59 +00:00
Add Quaternion to rotation matrix
This commit is contained in:
parent
fc6339564a
commit
a2cf92dd69
@ -8,6 +8,7 @@
|
||||
#ifndef STA_PEAK_QUATERNION_HPP
|
||||
#define STA_PEAK_QUATERNION_HPP
|
||||
|
||||
#include <sta/math/linalg/matrix.hpp>
|
||||
namespace sta
|
||||
{
|
||||
namespace math {
|
||||
@ -24,6 +25,8 @@ namespace sta
|
||||
|
||||
float norm();
|
||||
|
||||
matrix toRotationMatrix();
|
||||
|
||||
Quaternion normalized();
|
||||
|
||||
Quaternion operator*(const Quaternion& quat);
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user