Class of quaternion. More...
#include <MC_quaternion.hpp>


Public Member Functions | |
| MC_quaternion () | |
| zero contructor (set unitary axis (0,0,1) and zero angle ) | |
| MC_quaternion (const MC_v3d &axis, const double &angle) | |
| constructor from axis and angle | |
| MC_quaternion (const MC_v4d &v) | |
| constructor from base class: v4d | |
| MC_quaternion (const MC_quaternion &q) | |
| copy constructor | |
| MC_quaternion (const double &x, const double &y, const double &z, const double &w) | |
| direct constructor from coefficients | |
| MC_matrix | matrix () const |
| compute the rotation matrix associated to the current quaternion | |
| MC_quaternion | conjugated () const |
| get the conjugate of the current quaterion | |
| MC_quaternion & | operator*= (const MC_quaternion &q1) |
| internal multiplication between quaternion | |
| MC_quaternion | pow (const double &t) const |
| power of a quaternion with a double | |
| MC_quaternion | inverted () const |
| invert the quaternion | |
| MC_v3d | log () const |
| log map | |
| MC_v3d | axis () const |
| get the unit axis corresponding to the quaternion | |
| double | angle () const |
| get the angle corresponding to the quaternion | |
Static Public Member Functions | |
| static MC_quaternion | exp (const MC_v3d &v) |
| exp map | |
| static MC_quaternion | slerp (const MC_quaternion &q0, const MC_quaternion &q1, const double &t) |
| Spherical Linear Interpolation SLERP. | |
| static MC_quaternion | quat_interp (const std::vector< MC_quaternion > &quaternion_vec, const MC_double_vector &weights) |
| static MC_matrix | quat_interp (const std::vector< MC_matrix > &matrix_vec, const MC_double_vector &weights) |
| Generalized approximate spherical interpolation for rotation and linear one for translation. | |
| static MC_matrix | quat_interp (const std::vector< MC_quaternion > &quaternion_vec, const MC_double_vector &weights, const MC_v3d_vector &translation_vec) |
| Generalized approximate spherical interpolation for rotation and linear one for translation. | |
Friends | |
| MC_quaternion | operator* (const MC_quaternion &q0, const MC_quaternion &q1) |
| multiplication between quaternion | |
Class of quaternion.
internally based on v4d (axis_x,axis_y,axis_z,angle)
Definition at line 43 of file MC_quaternion.hpp.
| mesh_conv::MC_quaternion::MC_quaternion | ( | ) |
zero contructor (set unitary axis (0,0,1) and zero angle )
Definition at line 13 of file MC_quaternion.cpp.
Referenced by exp(), and quat_interp().
00014 :MC_v4d(1,0,0,0) 00015 {}

| mesh_conv::MC_quaternion::MC_quaternion | ( | const MC_v3d & | axis, | |
| const double & | angle | |||
| ) |
constructor from axis and angle
Definition at line 16 of file MC_quaternion.cpp.
References mesh_conv::MC_v4d::MC_v4d(), and mesh_conv::MC_v3d::normalized().
00017 :MC_v4d(0,0,0,0) 00018 { 00019 double sin_phi=sin(angle/2.0); 00020 MC_v3d n_axis=axis.normalized(); 00021 *this=MC_v4d(n_axis[0]*sin_phi,n_axis[1]*sin_phi,n_axis[2]*sin_phi,cos(angle/2.0)); 00022 }

| mesh_conv::MC_quaternion::MC_quaternion | ( | const MC_v4d & | v | ) |
constructor from base class: v4d
Definition at line 23 of file MC_quaternion.cpp.
| mesh_conv::MC_quaternion::MC_quaternion | ( | const MC_quaternion & | q | ) |
copy constructor
Definition at line 26 of file MC_quaternion.cpp.
00027 :MC_v4d(q[0],q[1],q[2],q[3]) 00028 {}
| mesh_conv::MC_quaternion::MC_quaternion | ( | const double & | x, | |
| const double & | y, | |||
| const double & | z, | |||
| const double & | w | |||
| ) |
direct constructor from coefficients
Definition at line 29 of file MC_quaternion.cpp.
00030 :MC_v4d(x,y,z,w) 00031 {}
| double mesh_conv::MC_quaternion::angle | ( | ) | const |
get the angle corresponding to the quaternion
Definition at line 96 of file MC_quaternion.cpp.
| MC_v3d mesh_conv::MC_quaternion::axis | ( | ) | const |
get the unit axis corresponding to the quaternion
Definition at line 94 of file MC_quaternion.cpp.
References mesh_conv::MC_v3d::normalized().

| MC_quaternion mesh_conv::MC_quaternion::conjugated | ( | ) | const |
get the conjugate of the current quaterion
Definition at line 61 of file MC_quaternion.cpp.
Referenced by mesh_conv::MC_trackball::apply_rotation(), mesh_conv::MC_navigator_tool::current_cam1(), mesh_conv::MC_navigator_tool::current_light1(), display_callback(), draw_orientation(), draw_pointer(), mesh_conv::MC_navigator_tool::go_forward_trackball_cam1(), mesh_conv::MC_navigator_tool::go_right_trackball_cam1(), mesh_conv::MC_navigator_tool::go_up_trackball_cam1(), inverted(), motion_callback(), mesh_conv::operator*(), and mesh_conv::MC_v3d::operator*=().
00062 { 00063 MC_quaternion q2; 00064 for(int k_dim=0;k_dim<3;k_dim++) 00065 q2[k_dim]=-(*this)[k_dim]; 00066 q2[3]=(*this)[3]; 00067 return q2; 00068 }
| MC_quaternion mesh_conv::MC_quaternion::exp | ( | const MC_v3d & | v | ) | [static] |
exp map
the exp is going from R3 -> S3
Definition at line 136 of file MC_quaternion.cpp.
References MC_quaternion(), and mesh_conv::MC_v3d::norm().
Referenced by pow().
00137 { 00138 double epsilon=0.000001; 00139 double n=v.norm(); 00140 if(n<epsilon) 00141 return MC_quaternion(0,0,0,1); 00142 00143 double a = sin(n)/n; 00144 00145 return MC_quaternion(a*v[0],a*v[1],a*v[2],cos(n)); 00146 }


| MC_quaternion mesh_conv::MC_quaternion::inverted | ( | ) | const |
invert the quaternion
Definition at line 114 of file MC_quaternion.cpp.
References conjugated(), and mesh_conv::MC_v4d::norm().
00115 { 00116 double n=norm(); 00117 double epsilon=0.000001; 00118 if(n<epsilon) 00119 {std::cout<<"Error in Quaternion::invert(), norm is zero"<<std::endl;exit(-1);} 00120 00121 MC_quaternion Q = conjugated()/(n*n); 00122 return Q; 00123 }

| MC_v3d mesh_conv::MC_quaternion::log | ( | ) | const |
log map
the log is going from S3 -> R3
Definition at line 124 of file MC_quaternion.cpp.
Referenced by pow().
00125 { 00126 00127 double n=sqrt(1-(*this)[3]*(*this)[3]); 00128 double acos_w = acos((*this)[3]); 00129 00130 double epsilon=0.0001; 00131 if(n<epsilon) 00132 return MC_v3d(0,0,0); 00133 00134 return acos_w/n*MC_v3d((*this)[0],(*this)[1],(*this)[2]); 00135 }

| MC_matrix mesh_conv::MC_quaternion::matrix | ( | ) | const |
compute the rotation matrix associated to the current quaternion
Definition at line 33 of file MC_quaternion.cpp.
Referenced by mesh_conv::MC_navigator_tool::current_cam1(), mesh_conv::MC_navigator_tool::current_light1(), display_callback(), draw_orientation(), draw_pointer(), and quat_interp().
00034 { 00035 double x2 = (*this)[0]*(*this)[0]; 00036 double y2 = (*this)[1]*(*this)[1]; 00037 double z2 = (*this)[2]*(*this)[2]; 00038 double xy = (*this)[0]*(*this)[1]; 00039 double xz = (*this)[0]*(*this)[2]; 00040 double yz = (*this)[1]*(*this)[2]; 00041 double wx = (*this)[3]*(*this)[0]; 00042 double wy = (*this)[3]*(*this)[1]; 00043 double wz = (*this)[3]*(*this)[2]; 00044 00045 MC_matrix M(3,3); 00046 M(0,0) = 1-2*(y2+z2); 00047 M(1,0) = 2*(xy+wz); 00048 M(2,0) = 2*(xz-wy); 00049 00050 M(0,1) = 2*(xy-wz); 00051 M(1,1) = 1-2*(x2+z2); 00052 M(2,1) = 2*(yz+wx); 00053 00054 M(0,2) = 2*(xz+wy); 00055 M(1,2) = 2*(yz-wx); 00056 M(2,2) = 1-2*(x2+y2); 00057 00058 return M; 00059 }

| MC_quaternion & mesh_conv::MC_quaternion::operator*= | ( | const MC_quaternion & | q1 | ) |
internal multiplication between quaternion
Definition at line 81 of file MC_quaternion.cpp.
References mesh_conv::MC_v3d::cross(), mesh_conv::MC_v3d::dot(), and mesh_conv::MC_v4d::set_v3d().
00082 { 00083 00084 double w0=(*this)[3],w1=q1[3]; 00085 MC_v3d v0=MC_v3d((*this)[0],(*this)[1],(*this)[2]); 00086 MC_v3d v1=MC_v3d(q1[0],q1[1],q1[2]); 00087 00088 (*this)[3]=w0*w1-v0.dot(v1); 00089 set_v3d(w0*v1+w1*v0-v0.cross(v1)); 00090 00091 return *this; 00092 }

| MC_quaternion mesh_conv::MC_quaternion::pow | ( | const double & | t | ) | const |
power of a quaternion with a double
Definition at line 112 of file MC_quaternion.cpp.
00113 {return MC_quaternion::exp( t * log());}

| MC_matrix mesh_conv::MC_quaternion::quat_interp | ( | const std::vector< MC_quaternion > & | quaternion_vec, | |
| const MC_double_vector & | weights, | |||
| const MC_v3d_vector & | translation_vec | |||
| ) | [static] |
Generalized approximate spherical interpolation for rotation and linear one for translation.
Definition at line 163 of file MC_quaternion.cpp.
References matrix(), quat_interp(), mesh_conv::MC_matrix::set_block(), mesh_conv::MC_v3d_vector::size(), mesh_conv::MC_double_vector::size(), and mesh_conv::MC_v3d_vector::sum().
00164 { 00165 MC_matrix res(4,4); 00166 00167 if(weights.size()!=translation_vec.size()) 00168 {std::cout<<"Error in MC_quaternion::quat_interp(vector<MC_quaternion>("<<quaternion_vec.size()<<"),MC_double_vector("<<weights.size()<<"),MC_v3d_vector("<<translation_vec.size()<<")), size are not compatible"<<std::endl;exit(-1);} 00169 00170 //first do the rotation 00171 MC_quaternion rot = MC_quaternion::quat_interp(quaternion_vec,weights); 00172 res.set_block(0,2,0,2,rot.matrix()); 00173 00174 //then the translation by linear interpolation 00175 MC_v3d tr = MC_v3d_vector::sum(weights*translation_vec); 00176 res.set_block(0,2,3,3,tr); 00177 res(3,3)=1; 00178 00179 return res; 00180 00181 }

| MC_matrix mesh_conv::MC_quaternion::quat_interp | ( | const std::vector< MC_matrix > & | matrix_vec, | |
| const MC_double_vector & | weights | |||
| ) | [static] |
Generalized approximate spherical interpolation for rotation and linear one for translation.
Definition at line 183 of file MC_quaternion.cpp.
References matrix(), MC_quaternion(), quat_interp(), mesh_conv::MC_matrix::set_block(), and mesh_conv::MC_double_vector::size().
00184 { 00185 if(static_cast<int>(matrix_vec.size()) !=weights.size()) 00186 {std::cout<<"Error in MC_quaternion::quat_interp(vector<MC_matrix>,MC_double_vector), size are not compatible ("<<matrix_vec.size()<<","<<weights.size()<<")"<<std::endl;exit(-1);} 00187 00188 int N=matrix_vec.size(); 00189 00190 // rotation 00191 std::vector <MC_quaternion> quaternion_vec(N); 00192 for(int k=0;k<N;k++) 00193 quaternion_vec[k] = MC_quaternion(matrix_vec[k]); 00194 MC_quaternion res = MC_quaternion::quat_interp(quaternion_vec,weights); 00195 00196 // translation 00197 MC_v3d tr; 00198 for(int k=0;k<N;k++) 00199 tr += weights[k]*(matrix_vec[k].translation_part()); 00200 00201 00202 MC_matrix interpolated_matrix(4,4); 00203 interpolated_matrix.set_block(0,2,0,2,res.matrix()); 00204 interpolated_matrix.set_block(0,2,3,3,tr); 00205 00206 00207 return interpolated_matrix; 00208 00209 }

| MC_quaternion mesh_conv::MC_quaternion::quat_interp | ( | const std::vector< MC_quaternion > & | quaternion_vec, | |
| const MC_double_vector & | weights | |||
| ) | [static] |
Generalized approximate spherical interpolation for rotation
Compute sum(qi)/norm(sum(qi))
Definition at line 150 of file MC_quaternion.cpp.
References mesh_conv::MC_v4d::norm(), and mesh_conv::MC_double_vector::size().
Referenced by quat_interp().
00151 { 00152 if(int(quaternion_vec.size())!=weights.size()) 00153 {std::cout<<"Error in MC_quaternion::quat_interp(vector<MC_quaternion>,MC_double_vector), size are not compatible ("<<quaternion_vec.size()<<","<<weights.size()<<")"<<std::endl;exit(-1);} 00154 00155 MC_quaternion temp(0,0,0,0); 00156 int N=quaternion_vec.size(); 00157 for(int k=0;k<N;k++) 00158 temp += weights[k]*quaternion_vec[k]; 00159 temp /= temp.norm(); 00160 return temp; 00161 }


| MC_quaternion mesh_conv::MC_quaternion::slerp | ( | const MC_quaternion & | q0, | |
| const MC_quaternion & | q1, | |||
| const double & | t | |||
| ) | [static] |
Spherical Linear Interpolation SLERP.
Use (sin((1-t) theta )q0 +sin(t theta)q1)/sin(theta) But same results with (q1 q0^{-1})^{t} q0 (q1*q0.invert()).pow_q(t)*q0)
Definition at line 98 of file MC_quaternion.cpp.
References mesh_conv::MC_v4d::dot().
00099 { 00100 double cos_theta = q0.dot(q1); 00101 double theta = acos(cos_theta); 00102 double sin_theta = sqrt(1-cos_theta*cos_theta); 00103 00104 double epsilon=0.0001; 00105 if(fabs(sin_theta)<epsilon) 00106 {std::cout<<"Warning in Quaternion::SLERP, sin(theta) is zero"<<std::endl;return q0;} 00107 00108 MC_quaternion interpolated = (sin((1-t)*theta)*q0 + sin(t*theta)*q1) / sin_theta; 00109 return interpolated; 00110 }

| MC_quaternion operator* | ( | const MC_quaternion & | q0, | |
| const MC_quaternion & | q1 | |||
| ) | [friend] |
multiplication between quaternion
1.6.1