EMAN2
quaternion.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman__quaternion_h__
33#define eman__quaternion_h__ 1
34
35#include "vec3.h"
36
37namespace EMAN
38{
62 {
63 public:
64 Quaternion();
65 Quaternion(float e0, float e1, float e2, float e3);
66 Quaternion(float radians, const Vec3f &axis);
67 Quaternion(const Vec3f &axis, float radians);
68 explicit Quaternion(const vector<float> & matrix3);
69
71 {
72 }
73
74 float norm() const
75 {
76 return (e0 * e0 + e1 * e1 + e2 * e2 + e3 * e3);
77 }
78
80 {
81 return (Quaternion(e0, -e1, -e2, -e3));
82 }
83
84 float abs() const
85 {
86 return sqrt(norm());
87 }
88
89 void normalize();
92
93 Vec3f rotate(const Vec3f &v) const;
94
95 float to_angle() const;
96 Vec3f to_axis() const;
97
98 vector<float> to_matrix3() const;
99
100 float real() const;
101 Vec3f unreal() const;
102
103 vector < float > as_list() const;
104
105 Quaternion & operator+=(const Quaternion & q);
106 Quaternion & operator-=(const Quaternion & q);
107 Quaternion & operator*=(const Quaternion & q);
108 Quaternion & operator*=(float s);
109 Quaternion & operator/=(const Quaternion & q);
110 Quaternion & operator/=(float s);
111
112 static Quaternion interpolate(const Quaternion & from, const Quaternion & to,
113 float percent);
114 private:
115 float e0;
116 float e1;
117 float e2;
118 float e3;
119 };
120
121 Quaternion operator+(const Quaternion & q1, const Quaternion & q2);
122 Quaternion operator-(const Quaternion & q1, const Quaternion & q2);
123
124 Quaternion operator*(const Quaternion & q1, const Quaternion & q2);
125 Quaternion operator*(const Quaternion & q, float s);
126 Quaternion operator*(float s, const Quaternion & q);
127 Quaternion operator/(const Quaternion & q1, const Quaternion & q2);
128
129 bool operator==(const Quaternion & q1, const Quaternion & q2);
130 bool operator!=(const Quaternion & q1, const Quaternion & q2);
131}
132
133#endif //eman__quaternion_h__
Quaternion is used in Rotation and Transformation to replace Euler angles.
Definition: quaternion.h:62
vector< float > to_matrix3() const
Definition: quaternion.cpp:187
static Quaternion interpolate(const Quaternion &from, const Quaternion &to, float percent)
Definition: quaternion.cpp:372
Vec3f unreal() const
Definition: quaternion.cpp:213
Vec3f rotate(const Vec3f &v) const
Definition: quaternion.cpp:145
float norm() const
Definition: quaternion.h:74
Quaternion & operator*=(const Quaternion &q)
Definition: quaternion.cpp:247
Quaternion & inverse()
Definition: quaternion.cpp:128
vector< float > as_list() const
Definition: quaternion.cpp:218
Quaternion conj() const
Definition: quaternion.h:79
Quaternion create_inverse() const
Definition: quaternion.cpp:138
Quaternion & operator/=(const Quaternion &q)
Definition: quaternion.cpp:274
Quaternion & operator+=(const Quaternion &q)
Definition: quaternion.cpp:229
Vec3f to_axis() const
Definition: quaternion.cpp:171
float to_angle() const
Definition: quaternion.cpp:156
float abs() const
Definition: quaternion.h:84
Quaternion & operator-=(const Quaternion &q)
Definition: quaternion.cpp:238
float real() const
Definition: quaternion.cpp:208
EMData * sqrt() const
return square root of current image
E2Exception class.
Definition: aligner.h:40
EMData * operator+(const EMData &em, float n)
Definition: emdata.cpp:3187
bool operator!=(const EMObject &e1, const EMObject &e2)
Definition: emobject.cpp:873
EMData * operator-(const EMData &em, float n)
Definition: emdata.cpp:3194
EMData * operator/(const EMData &em, float n)
Definition: emdata.cpp:3208
EMData * operator*(const EMData &em, float n)
Definition: emdata.cpp:3201
bool operator==(const EMObject &e1, const EMObject &e2)
Definition: emobject.cpp:770