58 const base_type& vec()
const {
return *
this; }
80 this->
w() = sqrt(
plus(T(0.25)*( M(0, 0) + M(1, 1) + M(2, 2) + T(1))));
81 this->
x() = sqrt(
plus(T(0.25)*( M(0, 0) - M(1, 1) - M(2, 2) + T(1))));
82 this->
y() = sqrt(
plus(T(0.25)*(-M(0, 0) + M(1, 1) - M(2, 2) + T(1))));
83 this->
z() = sqrt(
plus(T(0.25)*(-M(0, 0) - M(1, 1) + M(2, 2) + T(1))));
84 if (this->
w() >= this->
x() && this->
w() >= this->
y() && this->
w() >= this->
z()) {
85 this->
x() *=
sign(M(2, 1) - M(1, 2));
86 this->
y() *=
sign(M(0, 2) - M(2, 0));
87 this->
z() *=
sign(M(1, 0) - M(0, 1));
89 else if (this->
x() >= this->
y() && this->
x() >= this->
z()) {
90 this->
w() *=
sign(M(2, 1) - M(1, 2));
91 this->
y() *=
sign(M(0, 1) + M(1, 0));
92 this->
z() *=
sign(M(2, 0) + M(0, 2));
94 else if (this->
y() >= this->
z()) {
95 this->
w() *=
sign(M(0, 2) - M(2, 0));
96 this->
x() *=
sign(M(0, 1) + M(1, 0));
97 this->
z() *=
sign(M(1, 2) + M(2, 1));
100 this->
w() *=
sign(M(1, 0) - M(0, 1));
101 this->
x() *=
sign(M(0, 2) + M(2, 0));
102 this->
y() *=
sign(M(1, 2) + M(2, 1));
124 M(0, 0) = 1 - 2 * this->
y()*this->
y() - 2 * this->
z()*this->
z();
125 M(0, 1) = 2 * this->
x()*this->
y() - 2 * this->
w()*this->
z();
126 M(0, 2) = 2 * this->
x()*this->
z() + 2 * this->
w()*this->
y();
127 M(1, 0) = 2 * this->
x()*this->
y() + 2 * this->
w()*this->
z();
128 M(1, 1) = 1 - 2 * this->
x()*this->
x() - 2 * this->
z()*this->
z();
129 M(1, 2) = 2 * this->
y()*this->
z() - 2 * this->
w()*this->
x();
130 M(2, 0) = 2 * this->
x()*this->
z() - 2 * this->
w()*this->
y();
131 M(2, 1) = 2 * this->
y()*this->
z() + 2 * this->
w()*this->
x();
132 M(2, 2) = 1-2*this->
x()*this->
x()-2*this->
y()*this->
y();
139 M(0, 0) = 1 - 2 * this->
y()*this->
y() - 2 * this->
z()*this->
z();
140 M(0, 1) = 2 * this->
x()*this->
y() - 2 * this->
w()*this->
z();
141 M(0, 2) = 2 * this->
x()*this->
z() + 2 * this->
w()*this->
y();
142 M(1, 0) = 2 * this->
x()*this->
y() + 2 * this->
w()*this->
z();
143 M(1, 1) = 1 - 2 * this->
x()*this->
x() - 2 * this->
z()*this->
z();
144 M(1, 2) = 2 * this->
y()*this->
z() - 2 * this->
w()*this->
x();
145 M(2, 0) = 2 * this->
x()*this->
z() - 2 * this->
w()*this->
y();
146 M(2, 1) = 2 * this->
y()*this->
z() + 2 * this->
w()*this->
x();
147 M(2, 2) = 1 - 2 * this->
x()*this->
x() - 2 * this->
y()*this->
y();
148 M(3,0) = M(3,1) = M(3,2) = M(0,3) = M(1, 3) = M(2, 3) = M(3, 3) = 0;
157 if (fabs(cosfac)<EPSILON)
160 cosfac = sqrt(cosfac);
164 set(fac*sinfac/cosfac, 0, -n.
z()*tmp, n.
y()*tmp);
170 n[0] = 1-2*(this->
y()*this->
y()+ this->
z()*this->
z());
171 n[1] = 2*(this->
w()*this->
z() + this->
x()*this->
y());
172 n[2] = 2*(this->
x()*this->
z() - this->
w()*this->
y());
196 preimage =
cross(-
im(), image);
213 void conjugate() { this->
x() = -this->
x(); this->
y() = -this->
y(); this->
z() = -this->
z(); }
221 if (sn < EPSILON*EPSILON)
232 if ( ( 1 + cosom) > EPSILON ) {
233 if ( ( 1 - cosom) > EPSILON ) {
234 omega = acos( cosom );
235 sinom = sin ( omega );
236 sclp = sin ( (1-t) * omega ) / sinom;
237 sclq = sin ( t*omega ) / sinom;
244 set(sclp*p.w() + sclq*q.
w(), sclp*p.x() + sclq*q.
x(), sclp*p.y() + sclq*q.
y(), sclp*p.z() + sclq*q.
z());
247 sclp = (T)sin ( (1-t)*M_PI/2 );
248 sclq = (T)sin ( t * M_PI/2 );
249 set(p.z(), sclp*p.x() - sclq*p.y(), sclp*p.y() + sclq*p.x(), sclp*p.z() - sclq*p.w());
261 s[0] = (this->
z()-this->
y())*(q.
y()-q.
z());
262 s[1] = (this->
w()+this->
x())*(q.
w()+q.
x());
263 s[2] = (this->
w()-this->
x())*(q.
y()+q.
z());
264 s[3] = (this->
z()+this->
y())*(q.
w()-q.
x());
265 s[4] = (this->
z()-this->
x())*(q.
x()-q.
y());
266 s[5] = (this->
z()+this->
x())*(q.
x()+q.
y());
267 s[6] = (this->
w()+this->
y())*(q.
w()-q.
z());
268 s[7] = (this->
w()-this->
y())*(q.
w()+q.
z());
269 s[8] = s[5]+s[6]+s[7];
271 set(s[0]+t-s[5], s[1]+t-s[8], s[2]+t-s[7], s[3]+t-s[6]);
286 coord_type&
re() {
return this->
w(); }
288 void put_im(vec_type& vector)
const { vector.
x() = this->
x(); vector.
y() = this->
y(); vector.
z() = this->
z(); }
325 T sinTimesR = v.length();
326 if (sinTimesR < EPSILON)
338 template <
typename T>
quaternion< T > negated() const
return the negated quaternion
Definition: quaternion.h:209
quaternion< T > & operator=(const quaternion< T > &quat)
assignement operator
Definition: quaternion.h:43
AxisEnum
enumeration of the three coordinate axes
Definition: quaternion.h:24
double normalize()
normalize the vector using the L2-Norm and return the length
Definition: fvec.h:260
matrix of fixed size dimensions
Definition: fmat.h:23
quaternion(coord_type w, coord_type x, coord_type y, coord_type z)
construct quaternion directly
Definition: quaternion.h:54
void set(const mat_type &M)
initialize quaternion from 3x3 rotation matrix
Definition: quaternion.h:78
T sign(const T &a, const T &b)
returns the abs(a)*sign(b)
Definition: functions.h:15
void inverse_rotate(vec_type &image) const
rotate vector according to the inverse quaternion
Definition: quaternion.h:200
void negate()
negate the quaternion
Definition: quaternion.h:211
quaternion(const mat_type &matrix)
construct quaternion from 3x3 rotation matrix
Definition: quaternion.h:52
quaternion(AxisEnum axis, coord_type angle)
construct quaternion from coordinate axis and rotation angle
Definition: quaternion.h:48
T length() const
length of the vector L2-Norm
Definition: fvec.h:219
void set(const vec_type &axis, coord_type angle)
initialize quaternion from axis and rotation angle
Definition: quaternion.h:70
T & y()
second element
Definition: fvec.h:133
mat_type get_rotated(const mat_type &M) const
Rotate source frame s into destination frame d.
Definition: quaternion.h:192
fvec< T, N > cross(const fvec< T, N > &v, const fvec< T, N > &w)
returns the cross product of vector v and w
Definition: fvec.h:338
vec_type get_rotated(const vec_type &v) const
return rotated vector
Definition: quaternion.h:183
void put_image(const vec_type &preimage, vec_type &image) const
rotate preimage according to quaternion into image
Definition: quaternion.h:175
void put_im(vec_type &vector) const
put imaginary part
Definition: quaternion.h:288
quaternion< T > operator*(const quaternion< T > &q) const
field multiplication
Definition: quaternion.h:275
vec_type apply(const vec_type &v) const
rotate vector according to quaternion
Definition: quaternion.h:202
Definition: quaternion.h:15
void conjugate()
compute conjugate
Definition: quaternion.h:213
A column vector class.
Definition: fvec.h:13
void put_preimage(const vec_type &image, vec_type &preimage) const
rotate image according to quaternion into preimage
Definition: quaternion.h:194
T & w()
fourth element
Definition: fvec.h:141
vec_type im() const
return this as vector
Definition: quaternion.h:290
fvec< T, N > & operator*=(const T &s)
in place multiplication with s
Definition: fvec.h:163
T plus(const T &v)
if v >= 0 returns v or 0 otherwise
Definition: functions.h:21
coord_type put_axis(vec_type &v) const
put rotation axis and return rotation angle
Definition: quaternion.h:292
quaternion< T > & operator*=(const quaternion< T > &q)
field multiplication
Definition: quaternion.h:257
void put_homogeneous_matrix(hmat_type &M) const
compute equivalent homogeneous 4x4 rotation matrix
Definition: quaternion.h:137
quaternion< T > inverse() const
return the inverse
Definition: quaternion.h:215
T coord_type
coordinate type
Definition: quaternion.h:22
quaternion< T > exp() const
exponential map
Definition: quaternion.h:313
T sqr_length() const
square length of vector
Definition: fvec.h:252
fmat< T, 4, 4 > hmat_type
type of 4x4 matrix
Definition: quaternion.h:30
T & x()
first element
Definition: fvec.h:129
coord_type & re()
return reference to real part
Definition: quaternion.h:286
hmat_type get_homogeneous_matrix() const
return equivalent 4x4 rotation matrix
Definition: quaternion.h:152
void set(coord_type re, const vec_type &im)
initialize quaternion from real part and vector
Definition: quaternion.h:114
quaternion(const quaternion< S > &q)
copy constructor with type conversion
Definition: quaternion.h:41
fvec< T, 3 > vec_type
type of 3d axis
Definition: quaternion.h:26
quaternion< T > operator-() const
negation operator
Definition: quaternion.h:255
quaternion(const quaternion< T > &quat)
copy constructor
Definition: quaternion.h:38
void set(coord_type re, coord_type ix, coord_type iy, coord_type iz)
initialize quaternion directly
Definition: quaternion.h:106
fvec & operator=(const fvec< T, N > &rhs)
assign vector rhs, if vector and rhs have different sizes, vector has been resized to match the size ...
Definition: fvec.h:103
T dot(const fvec< T, N > &v, const fvec< T, N > &w)
returns the dot product of vector v and w
Definition: fvec.h:300
fvec< T, 4 > base_type
base class type
Definition: quaternion.h:20
void rotate(mat_type &m) const
Rotate a frame according to quaternion.
Definition: quaternion.h:185
quaternion()
standard constructor initializes to unit quaternion
Definition: quaternion.h:36
void set(const quaternion< T > &quat)
setter from quaternion
Definition: quaternion.h:76
void invert()
compute inverse
Definition: quaternion.h:217
T & z()
third element
Definition: fvec.h:137
quaternion< T > log() const
logarithmic map
Definition: quaternion.h:321
void put_normal(coord_type *n)
extract normal vector
Definition: quaternion.h:168
void put_matrix(mat_type &M) const
compute equivalent 3x3 rotation matrix
Definition: quaternion.h:122
void set(AxisEnum axis, coord_type angle)
initialize quaternion from coordinate axis and rotation angle
Definition: quaternion.h:63
mat_type get_matrix() const
return equivalent 3x3 rotation matrix
Definition: quaternion.h:135
quaternion(const vec_type &axis, coord_type angle)
construct quaternion from axis and rotation angle
Definition: quaternion.h:50
fmat< T, 3, 3 > mat_type
type of 3x3 matrix
Definition: quaternion.h:28
coord_type re() const
return real part
Definition: quaternion.h:284
quaternion(coord_type re, const vec_type &im)
construct quaternion from real part and vector
Definition: quaternion.h:56
void affin(const quaternion< T > &p, coord_type t, const quaternion< T > &q)
compute affin combination with angular interpolation
Definition: quaternion.h:227
void rotate(vec_type &v) const
rotate vector according to quaternion
Definition: quaternion.h:181
quaternion< T > conj() const
return the conjugate
Definition: quaternion.h:207
the cgv namespace
Definition: vr_calib.cxx:9
void set_normal(const vec_type &n)
initialize quaternion from normal vector
Definition: quaternion.h:154
void affin(coord_type s, const quaternion< T > &q)
compute affin combination with angular interpolation
Definition: quaternion.h:253
fvec< T, N > & operator/=(const T &s)
in place division by scalar s
Definition: fvec.h:165