36Quaternion::Quaternion()
37: e0(0), e1(0), e2(0), e3(0)
46 q *= sin(radians / 2.0f);
47 e0 = cos(radians / 2.0f);
59 q *= sin(radians / 2.0f);
60 e0 = cos(radians / 2.0f);
68:e0(ee0), e1(ee1), e2(ee2), e3(ee3)
94 if (m[0] + m[4] + m[8] > m[i*3+i]) {
95 e0 = (float) (
sqrt(m[0] + m[4] + m[8] + 1) / 2.0);
96 e1 = (float) ((m[5] - m[7]) / (4 *
e0));
97 e2 = (float) ((m[6] - m[2]) / (4 *
e0));
98 e3 = (float) ((m[1] - m[3]) / (4 *
e0));
105 quat[i] = (float) (
sqrt(m[i*3+i] - m[j*3+j] - m[k*3+k] + 1) / 2.0);
106 quat[j] = (float) ((m[i*3+j] + m[j*3+i]) / (4 * quat[i]));
107 quat[k] = (float) ((m[i*3+k] + m[k*3+i]) / (4 * quat[i]));
109 e0 = (float) ((m[j*3+k] - m[k*3+j]) / (4 * quat[i]));
130 float f = 1.0f /
norm();
150 Vec3f rotated = v + v1 - v2;
162 if (len > 0.00001f) {
163 radians = 2.0f * acos(
e0);
177 if (len > 0.00001f) {
178 axis = q * ((float) (1.0f / len));
189 vector < float >m(9);
220 vector < float >v(4);
351 const float err_limit = 0.00001f;
353 vector < float >v1 = q1.
as_list();
354 vector < float >v2 = q2.
as_list();
356 for (
size_t i = 0; i < v1.size(); i++) {
357 if (fabs(v1[i] - v2[i]) > err_limit) {
368 return (!(q1 == q2));
375 const double epsilon = 0.00001;
376 double cosom = from.
e1 * to.
e1 + from.
e2 * to.
e2 + from.
e3 * to.
e3 + from.
e0 * to.
e0;
387 double scale0 = 1 - t;
390 if ((1 - cosom) > epsilon) {
391 double omega = acos(cosom);
392 double sinom = sin(omega);
393 scale0 = sin((1 - t) * omega) / sinom;
394 scale1 = sin(t * omega) / sinom;
397 float scale0f = (float) scale0;
398 float scale1f = (float) scale1;
400 return (scale0f * from + scale1f * q);
Quaternion is used in Rotation and Transformation to replace Euler angles.
vector< float > to_matrix3() const
static Quaternion interpolate(const Quaternion &from, const Quaternion &to, float percent)
Vec3f rotate(const Vec3f &v) const
Quaternion & operator*=(const Quaternion &q)
vector< float > as_list() const
Quaternion create_inverse() const
Quaternion & operator/=(const Quaternion &q)
Quaternion & operator+=(const Quaternion &q)
Quaternion & operator-=(const Quaternion &q)
Vec3< Type > cross(const Vec3< Type2 > &v) const
Calculate the cross product of 'this' vector with a second vector.
void set_value(const vector< Type2 > &v)
Set new values using a std::vector object.
float length() const
Calculate its length.
EMData * sqrt() const
return square root of current image
EMData * operator+(const EMData &em, float n)
bool operator!=(const EMObject &e1, const EMObject &e2)
EMData * operator-(const EMData &em, float n)
EMData * operator/(const EMData &em, float n)
EMData * operator*(const EMData &em, float n)
bool operator==(const EMObject &e1, const EMObject &e2)