EMAN2
quaternion.h
Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  * 
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  * 
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  * 
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  * 
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  * 
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  * 
00034  * */
00035 
00036 #ifndef eman__quaternion_h__
00037 #define eman__quaternion_h__ 1
00038 
00039 #include "vec3.h"
00040 
00041 namespace EMAN
00042 {
00065         class Quaternion
00066         {
00067           public:
00068                 Quaternion();
00069                 Quaternion(float e0, float e1, float e2, float e3);
00070                 Quaternion(float radians, const Vec3f &axis);
00071                 Quaternion(const Vec3f &axis, float radians);
00072                 explicit Quaternion(const vector<float> & matrix3);
00073                 
00074                 ~Quaternion()
00075                 {
00076                 }
00077 
00078                 float norm() const
00079                 {
00080                         return (e0 * e0 + e1 * e1 + e2 * e2 + e3 * e3);
00081                 }
00082 
00083                 Quaternion conj() const
00084                 {
00085                         return (Quaternion(e0, -e1, -e2, -e3));
00086                 }
00087 
00088                 float abs() const
00089                 {
00090                         return sqrt(norm());
00091                 }
00092 
00093                 void normalize();
00094                 Quaternion & inverse();
00095                 Quaternion create_inverse() const;
00096 
00097                 Vec3f rotate(const Vec3f &v) const;
00098 
00099                 float to_angle() const;
00100                 Vec3f to_axis() const;
00101 
00102                 vector<float> to_matrix3() const;
00103 
00104                 float real() const;
00105                 Vec3f unreal() const;
00106 
00107                 vector < float > as_list() const;
00108 
00109                 Quaternion & operator+=(const Quaternion & q);
00110                 Quaternion & operator-=(const Quaternion & q);
00111                 Quaternion & operator*=(const Quaternion & q);
00112                 Quaternion & operator*=(float s);
00113                 Quaternion & operator/=(const Quaternion & q);
00114                 Quaternion & operator/=(float s);
00115 
00116                 static Quaternion interpolate(const Quaternion & from, const Quaternion & to,
00117                                                                           float percent);
00118           private:
00119                 float e0;
00120                 float e1;
00121                 float e2;
00122                 float e3;
00123         };
00124 
00125         Quaternion operator+(const Quaternion & q1, const Quaternion & q2);
00126         Quaternion operator-(const Quaternion & q1, const Quaternion & q2);
00127 
00128         Quaternion operator*(const Quaternion & q1, const Quaternion & q2);
00129         Quaternion operator*(const Quaternion & q, float s);
00130         Quaternion operator*(float s, const Quaternion & q);
00131         Quaternion operator/(const Quaternion & q1, const Quaternion & q2);
00132 
00133         bool operator==(const Quaternion & q1, const Quaternion & q2);
00134         bool operator!=(const Quaternion & q1, const Quaternion & q2);
00135 }
00136 
00137 #endif  //eman__quaternion_h__