2012-03-04 23:31:47 -04:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
|
|
|
|
// Copyright 2012 Andrew Tridgell, all rights reserved.
|
|
|
|
|
|
|
|
// This library is free software; you can redistribute it and / or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
#ifndef QUATERNION_H
|
|
|
|
#define QUATERNION_H
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
class Quaternion
|
|
|
|
{
|
|
|
|
public:
|
2012-08-17 03:20:14 -03:00
|
|
|
float q1, q2, q3, q4;
|
2012-03-04 23:31:47 -04:00
|
|
|
|
2012-08-17 03:20:14 -03:00
|
|
|
// constructor creates a quaternion equivalent
|
|
|
|
// to roll=0, pitch=0, yaw=0
|
|
|
|
Quaternion() {
|
|
|
|
q1 = 1; q2 = q3 = q4 = 0;
|
|
|
|
}
|
2012-03-04 23:31:47 -04:00
|
|
|
|
2012-08-17 03:20:14 -03:00
|
|
|
// setting constructor
|
|
|
|
Quaternion(const float _q1, const float _q2, const float _q3, const float _q4) :
|
|
|
|
q1(_q1), q2(_q2), q3(_q3), q4(_q4) {
|
|
|
|
}
|
2012-03-04 23:31:47 -04:00
|
|
|
|
2012-08-17 03:20:14 -03:00
|
|
|
// function call operator
|
|
|
|
void operator ()(const float _q1, const float _q2, const float _q3, const float _q4)
|
|
|
|
{
|
|
|
|
q1 = _q1; q2 = _q2; q3 = _q3; q4 = _q4;
|
|
|
|
}
|
2012-03-04 23:31:47 -04:00
|
|
|
|
2012-08-17 03:20:14 -03:00
|
|
|
// check if any elements are NAN
|
|
|
|
bool is_nan(void)
|
|
|
|
{
|
|
|
|
return isnan(q1) || isnan(q2) || isnan(q3) || isnan(q4);
|
|
|
|
}
|
2012-03-04 23:31:47 -04:00
|
|
|
|
2012-08-17 03:20:14 -03:00
|
|
|
// return the rotation matrix equivalent for this quaternion
|
|
|
|
void rotation_matrix(Matrix3f &m);
|
2012-03-10 01:44:22 -04:00
|
|
|
|
2012-08-17 03:20:14 -03:00
|
|
|
// convert a vector from earth to body frame
|
|
|
|
void earth_to_body(Vector3f &v);
|
2012-03-10 01:44:22 -04:00
|
|
|
|
|
|
|
// create a quaternion from Euler angles
|
2012-08-17 03:20:14 -03:00
|
|
|
void from_euler(float roll, float pitch, float yaw);
|
2012-03-10 01:44:22 -04:00
|
|
|
|
|
|
|
// create eulers from a quaternion
|
2012-08-17 03:20:14 -03:00
|
|
|
void to_euler(float *roll, float *pitch, float *yaw);
|
2012-03-04 23:31:47 -04:00
|
|
|
};
|
|
|
|
#endif // QUATERNION_H
|