mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-03-01 03:04:04 -04:00
AP_Math: added quaternion normalization
This commit is contained in:
parent
006cf58b2d
commit
90c41981ac
@ -87,3 +87,21 @@ void Quaternion::to_euler(float *roll, float *pitch, float *yaw) const
|
|||||||
1 - 2.0f*(q3*q3 + q4*q4));
|
1 - 2.0f*(q3*q3 + q4*q4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Quaternion::length(void) const
|
||||||
|
{
|
||||||
|
return sqrtf(sq(q1) + sq(q2) + sq(q3) + sq(q4));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Quaternion::normalize(void)
|
||||||
|
{
|
||||||
|
float quatMag = length();
|
||||||
|
if (quatMag > 1e-16f)
|
||||||
|
{
|
||||||
|
float quatMagInv = 1.0f/quatMag;
|
||||||
|
q1 *= quatMagInv;
|
||||||
|
q2 *= quatMagInv;
|
||||||
|
q3 *= quatMagInv;
|
||||||
|
q4 *= quatMagInv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -64,6 +64,9 @@ public:
|
|||||||
// create eulers from a quaternion
|
// create eulers from a quaternion
|
||||||
void to_euler(float *roll, float *pitch, float *yaw) const;
|
void to_euler(float *roll, float *pitch, float *yaw) const;
|
||||||
|
|
||||||
|
float length(void) const;
|
||||||
|
void normalize();
|
||||||
|
|
||||||
// allow a quaternion to be used as an array, 0 indexed
|
// allow a quaternion to be used as an array, 0 indexed
|
||||||
float & operator[](uint8_t i) {
|
float & operator[](uint8_t i) {
|
||||||
float *_v = &q1;
|
float *_v = &q1;
|
||||||
|
Loading…
Reference in New Issue
Block a user