Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1702 | - | 1 | // -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*- |
2 | |||
3 | // Copyright 2012 Andrew Tridgell, all rights reserved. |
||
4 | |||
5 | // This library is free software; you can redistribute it and / or |
||
6 | // modify it under the terms of the GNU Lesser General Public |
||
7 | // License as published by the Free Software Foundation; either |
||
8 | // version 2.1 of the License, or (at your option) any later version. |
||
9 | |||
10 | #ifndef QUATERNION_H |
||
11 | #define QUATERNION_H |
||
12 | |||
13 | #include <math.h> |
||
14 | |||
15 | class Quaternion |
||
16 | { |
||
17 | public: |
||
18 | float q1, q2, q3, q4; |
||
19 | |||
20 | // constructor creates a quaternion equivalent |
||
21 | // to roll=0, pitch=0, yaw=0 |
||
22 | Quaternion() { q1 = 1; q2 = q3 = q4 = 0; } |
||
23 | |||
24 | // setting constructor |
||
25 | Quaternion(const float _q1, const float _q2, const float _q3, const float _q4): |
||
26 | q1(_q1), q2(_q2), q3(_q3), q4(_q4) {} |
||
27 | |||
28 | // function call operator |
||
29 | void operator ()(const float _q1, const float _q2, const float _q3, const float _q4) |
||
30 | { q1 = _q1; q2 = _q2; q3 = _q3; q4 = _q4; } |
||
31 | |||
32 | // check if any elements are NAN |
||
33 | bool is_nan(void) |
||
34 | { return isnan(q1) || isnan(q2) || isnan(q3) || isnan(q4); } |
||
35 | |||
36 | // return the rotation matrix equivalent for this quaternion |
||
37 | void rotation_matrix(Matrix3f &m); |
||
38 | |||
39 | // convert a vector from earth to body frame |
||
40 | void earth_to_body(Vector3f &v); |
||
41 | |||
42 | // create a quaternion from Euler angles |
||
43 | void from_euler(float roll, float pitch, float yaw); |
||
44 | |||
45 | // create eulers from a quaternion |
||
46 | void to_euler(float *roll, float *pitch, float *yaw); |
||
47 | }; |
||
48 | #endif // QUATERNION_H |