|
| 1 | +/** |
| 2 | + * @addtogroup quaternions Library for 3D Vectors & Quaternions |
| 3 | + * @{ |
| 4 | + * @file |
| 5 | + * @brief Generic header that provides data types for 3D vectors and quaternions |
| 6 | + * @author Krishna Vedala |
| 7 | + */ |
| 8 | + |
| 9 | +#ifndef __LIBQUAT_H_ |
| 10 | +#define __LIBQUAT_H_ |
| 11 | + |
| 12 | +/** Minimum recognizable value. Any value less than this is considered to be |
| 13 | + * @f$=0@f$ */ |
| 14 | +#define EPSILON 1e-9 |
| 15 | + |
| 16 | +/** |
| 17 | + * @addtogroup vec_3d 3D Vector operations |
| 18 | + * @{ |
| 19 | + */ |
| 20 | +/** 3D vector type */ |
| 21 | +typedef struct vec_3d_ |
| 22 | +{ |
| 23 | + float x; /**< X co-ordinate */ |
| 24 | + float y; /**< Y co-ordinate */ |
| 25 | + float z; /**< Z co-ordinate */ |
| 26 | +} vec_3d; |
| 27 | +/** @} */ |
| 28 | + |
| 29 | +/** |
| 30 | + * @addtogroup matrix Matrix operations |
| 31 | + * @{ |
| 32 | + */ |
| 33 | +/** A 3x3 Matrix type definition */ |
| 34 | +typedef struct mat_3x3_ |
| 35 | +{ |
| 36 | + union |
| 37 | + { /**< 3 element row 1 */ |
| 38 | + float row1[3]; |
| 39 | + vec_3d vec1; |
| 40 | + }; |
| 41 | + union |
| 42 | + { /**< 3 element row 2 */ |
| 43 | + float row2[3]; |
| 44 | + vec_3d vec2; |
| 45 | + }; |
| 46 | + union |
| 47 | + { /**< 3 element row 3 */ |
| 48 | + float row3[3]; |
| 49 | + vec_3d vec3; |
| 50 | + }; |
| 51 | +} mat_3x3; |
| 52 | +/** @} */ |
| 53 | + |
| 54 | +/** @addtogroup quats 3D Quaternion operations |
| 55 | + * @{ |
| 56 | + */ |
| 57 | +/** a Quaternion type represented using a scalar \f$w\f$ or \f$q_0\f$ and a |
| 58 | + * 3D vector \f$\left(q_1,q_2,q_3\right)\f$ |
| 59 | + */ |
| 60 | +typedef struct quaternion_ |
| 61 | +{ |
| 62 | + float w; /**< real part of quaternion */ |
| 63 | + /**< dual part of quaternion */ |
| 64 | + union |
| 65 | + { |
| 66 | + vec_3d dual; /**< can be a 3D vector */ |
| 67 | + /** or individual values */ |
| 68 | + struct |
| 69 | + { |
| 70 | + float q1, q2, q3; |
| 71 | + }; |
| 72 | + }; |
| 73 | +} quaternion; |
| 74 | + |
| 75 | +/** 3D Euler or Tait-Bryan angles (in radian) */ |
| 76 | +typedef struct euler_ |
| 77 | +{ |
| 78 | + float roll; /**< or bank \f$\phi\f$ = rotation about X axis */ |
| 79 | + float pitch; /**< or elevation \f$\theta\f$ = rotation about Y axis */ |
| 80 | + float yaw; /**< or heading \f$\psi\f$ = rotation about Z axis */ |
| 81 | +} euler; |
| 82 | + |
| 83 | +/** @} */ |
| 84 | + |
| 85 | +/** @addtogroup dual_quats 3D Dual-Quaternion operations |
| 86 | + * @{ |
| 87 | + */ |
| 88 | +/** a dual quaternion type */ |
| 89 | +typedef struct dual_quat_ |
| 90 | +{ |
| 91 | + quaternion real; /**< real part of dual quaternion */ |
| 92 | + quaternion dual; /**< dual part of dual quaternion */ |
| 93 | +} dual_quat; |
| 94 | + |
| 95 | +/** @} */ |
| 96 | + |
| 97 | +#endif // __LIBQUAT_H_ |
| 98 | + |
| 99 | +/** @} */ |
0 commit comments