70 using namespace NEWMAT;
87 cerr <<
"Quaternion::Quaternion, size of axis != 3" << endl;
92 Real norm_axis = sqrt(DotProduct(axis, axis));
96 cerr <<
"Quaternion::Quaternion(angle, axis), axis is not unit" << endl;
97 cerr <<
"Make the axis unit." << endl;
98 v_ = sin(angle/2) * axis/norm_axis;
101 v_ = sin(angle/2) * axis;
111 v_ = ColumnVector(3);
159 if( ((R.Nrows() == 3) && (R.Ncols() == 3)) ||
160 ((R.Nrows() == 4) && (R.Ncols() == 4)) )
162 Real tmp = fabs(R(1,1) + R(2,2) + R(3,3) + 1);
165 v_ = ColumnVector(3);
169 v_(1) = (R(3,2)-R(2,3))/(4*s_);
170 v_(2) = (R(1,3)-R(3,1))/(4*s_);
171 v_(3) = (R(2,1)-R(1,2))/(4*s_);
176 static int s_iNext[3] = { 2, 3, 1 };
178 if ( R(2,2) > R(1,1) )
180 if ( R(3,3) > R(2,2) )
182 int j = s_iNext[i-1];
183 int k = s_iNext[j-1];
185 Real fRoot = sqrt(R(i,i)-R(j,j)-R(k,k) + 1.0);
187 Real *tmp[3] = { &v_(1), &v_(2), &v_(3) };
188 *tmp[i-1] = 0.5*fRoot;
190 s_ = (R(k,j)-R(j,k))*fRoot;
191 *tmp[j-1] = (R(j,i)+R(i,j))*fRoot;
192 *tmp[k-1] = (R(k,i)+R(i,k))*fRoot;
197 cerr <<
"Quaternion::Quaternion: matrix input is not 3x3 or 4x4" << endl;
257 q.
s_ = s_ * rhs.s_ - DotProduct(v_, rhs.v_);
258 q.
v_ = s_ * rhs.v_ + rhs.s_ * v_ + CrossProduct(v_, rhs.v_);
267 return *
this*rhs.
i();
277 cerr <<
"Quaternion::set_v: input has a wrong size." << endl;
305 return( sqrt(s_*s_ + DotProduct(v_, v_)) );
330 return conjugate()/norm();
343 Real theta = sqrt(DotProduct(v_,v_)),
344 sin_theta = sin(theta);
347 if ( fabs(sin_theta) > EPSILON)
348 q.
v_ = v_*sin_theta/theta;
355 Quaternion Quaternion::power(
const Real t)
const
374 Real theta = acos(s_),
375 sin_theta = sin(theta);
377 if ( fabs(sin_theta) > EPSILON)
378 q.
v_ = v_/sin_theta*theta;
430 Matrix E(3,3), I(3,3);
433 if(
sign == BODY_FRAME)
452 return (s_*q.
s_ + v_(1)*q.
v_(1) + v_(2)*q.
v_(2) + v_(3)*q.
v_(3));
490 R = (1 - 2*DotProduct(v_, v_))*R + 2*v_*v_.t() + 2*s_*
x_prod_matrix(v_);
505 T.SubMatrix(1,3,1,3) = (1 - 2*DotProduct(v_, v_))*T.SubMatrix(1,3,1,3)
565 UpperTriangularMatrix U;
567 A = 0.5*q.
E(BASE_FRAME);
588 cerr <<
"Integ_Trap(quat1, quat2, dt): dt < 0. dt is set to 0." << endl;
595 dquat_present.
set_s(dquat_present.
s() );
596 dquat_present.
set_v(dquat_present.
v() );
601 dquat_past.
set_s(dquat_present.
s());
602 dquat_past.
set_v(dquat_present.
v());
613 Real integ = 0.5*(present.
s()+past.
s())*dt;
622 ColumnVector integ = 0.5*(present.
v()+past.
v())*dt;
680 if( (t < 0) || (t > 1) )
681 cerr <<
"Slerp(q0, q1, t): t < 0 or t > 1. t is set to 0." << endl;
684 return q0*((q0.
i()*q1).power(t));
686 return q0*((q0.
i()*-1*q1).power(t));
713 if( (t < 0) || (t > 1) )
714 cerr <<
"Slerp_prime(q0, q1, t): t < 0 or t > 1. t is set to 0." << endl;
717 return Slerp(q0, q1, t)*(q0.
i()*q1).Log();
719 return Slerp(q0, q1, t)*(q0.
i()*-1*q1).Log();
742 if( (t < 0) || (t > 1) )
743 cerr <<
"Squad(p,a,b,q, t): t < 0 or t > 1. t is set to 0." << endl;
791 if( (t < 0) || (t > 1) )
792 cerr <<
"Squad_prime(p,a,b,q, t): t < 0 or t > 1. t is set to 0." << endl;
798 U_prime = U*(p.
i()*q).Log(),
799 V_prime = V*(a.
i()*b).Log(),
800 W_prime = U.
i()*V_prime - U.power(-2)*U_prime*V;
802 q_squad = U*( W.power(2*t*(1-t))*W.Log()*(2-4*t) + W.power(2*t*(1-t)-1)*W_prime*2*t*(1-t) )
803 + U_prime*( W.power(2*t*(1-t)) );