📄 fgquaternion.h
字号:
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Header: FGQuaternion.h Author: Jon Berndt, Mathis Froehlich Date started: 12/02/98 ------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------------ ------- (C) 2004 Mathias Froehlich (Mathias.Froehlich@web.de) ---- This program 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 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Further information about the GNU Lesser General Public License can also be found on the world wide web at http://www.gnu.org.HISTORY-------------------------------------------------------------------------------12/02/98 JSB Created15/01/04 MF Quaternion class from old FGColumnVector4%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%SENTRY%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/#ifndef FGQUATERNION_H#define FGQUATERNION_H/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/#include <FGJSBBase.h>#include "FGMatrix33.h"#include "FGColumnVector3.h"#include <input_output/FGPropertyManager.h>/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/#define ID_QUATERNION "$Id$"namespace JSBSim {/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*//** Models the Quaternion representation of rotations. FGQuaternion is a representation of an arbitrary rotation through a quaternion. It has vector properties. This class also contains access functions to the euler angle representation of rotations and access to transformation matrices for 3D vectors. Transformations and euler angles are therefore computed once they are requested for the first time. Then they are cached for later usage as long as the class is not accessed trough a nonconst member function. Note: The order of rotations used in this class corresponds to a 3-2-1 sequence, or Y-P-R, or Z-Y-X, if you prefer. @see Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate School, January 1994 @see D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices", JSC 12960, July 1977 @see Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at NASA-Ames", NASA CR-2497, January 1975 @see Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics", Wiley & Sons, 1979 ISBN 0-471-03032-5 @see Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons, 1982 ISBN 0-471-08936-2 @author Mathias Froehlich, extended FGColumnVector4 originally by Tony Peden and Jon Berndt*//*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/class FGQuaternion : virtual FGJSBBase {public: /** Default initializer. Default initializer, initializes the class with the identity rotation. */ FGQuaternion() : mCacheValid(false) { Entry(1) = 1.0; Entry(2) = Entry(3) = Entry(4) = 0.0; } /** Copy constructor. Copy constructor, initializes the quaternion. @param q a constant reference to another FGQuaternion instance */ FGQuaternion(const FGQuaternion& q); /** Initializer by euler angles. Initialize the quaternion with the euler angles. @param phi The euler X axis (roll) angle in radians @param tht The euler Y axis (attitude) angle in radians @param psi The euler Z axis (heading) angle in radians */ FGQuaternion(double phi, double tht, double psi); /** Initializer by one euler angle. Initialize the quaternion with the single euler angle where its index is given in the first argument. @param idx Index of the euler angle to initialize @param angle The euler angle in radians */ FGQuaternion(int idx, double angle) : mCacheValid(false) { double angle2 = 0.5*angle; double Sangle2 = sin(angle2); double Cangle2 = cos(angle2); if (idx == ePhi) { Entry(1) = Cangle2; Entry(2) = Sangle2; Entry(3) = 0.0; Entry(4) = 0.0; } else if (idx == eTht) { Entry(1) = Cangle2; Entry(2) = 0.0; Entry(3) = Sangle2; Entry(4) = 0.0; } else { Entry(1) = Cangle2; Entry(2) = 0.0; Entry(3) = 0.0; Entry(4) = Sangle2; } } /// Destructor. ~FGQuaternion() {} /** Quaternion derivative for given angular rates. Computes the quaternion derivative which results from the given angular velocities @param PQR a constant reference to the body rate vector @return the quaternion derivative @see Stevens and Lewis, "Aircraft Control and Simulation", Second Edition, Equation 1.3-36. */ FGQuaternion GetQDot(const FGColumnVector3& PQR) const; /** Transformation matrix. @return a reference to the transformation/rotation matrix corresponding to this quaternion rotation. */ const FGMatrix33& GetT(void) const { ComputeDerived(); return mT; } /** Backward transformation matrix. @return a reference to the inverse transformation/rotation matrix corresponding to this quaternion rotation. */ const FGMatrix33& GetTInv(void) const { ComputeDerived(); return mTInv; } /** Retrieves the Euler angles. @return a reference to the triad of euler angles corresponding to this quaternion rotation. units radians */ const FGColumnVector3& GetEuler(void) const { ComputeDerived(); return mEulerAngles; } /** Retrieves the Euler angles. @param i the euler angle index. units radians. @return a reference to the i-th euler angles corresponding to this quaternion rotation. */ double GetEuler(int i) const { ComputeDerived(); return mEulerAngles(i); } /** Retrieves the Euler angles. @param i the euler angle index. @return a reference to the i-th euler angles corresponding to this quaternion rotation. units degrees */ double GetEulerDeg(int i) const { ComputeDerived(); return radtodeg*mEulerAngles(i); } /** Retrieves sine of the given euler angle. @return the sine of the Euler angle theta (pitch attitude) corresponding to this quaternion rotation. */ double GetSinEuler(int i) const { ComputeDerived(); return mEulerSines(i); } /** Retrieves cosine of the given euler angle. @return the sine of the Euler angle theta (pitch attitude) corresponding to this quaternion rotation. */ double GetCosEuler(int i) const { ComputeDerived(); return mEulerCosines(i); } /** Read access the entries of the vector. @param idx the component index. Return the value of the matrix entry at the given index. Indices are counted starting with 1. Note that the index given in the argument is unchecked. */ double operator()(unsigned int idx) const { return Entry(idx); } /** Write access the entries of the vector. @param idx the component index. Return a reference to the vector entry at the given index. Indices are counted starting with 1. Note that the index given in the argument is unchecked. */ double& operator()(unsigned int idx) { return Entry(idx); } /** Read access the entries of the vector. @param idx the component index. Return the value of the matrix entry at the given index. Indices are counted starting with 1. This function is just a shortcut for the <tt>double operator()(unsigned int idx) const</tt> function. It is used internally to access the elements in a more convenient way. Note that the index given in the argument is unchecked. */ double Entry(unsigned int idx) const { return mData[idx-1]; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -