49 #include <visp/vpMath.h>
50 #include <visp/vpMatrix.h>
53 #include <visp/vpRotationMatrix.h>
57 #include <visp/vpException.h>
58 #include <visp/vpMatrixException.h>
61 #include <visp/vpDebug.h>
63 const double vpRotationMatrix::threshold = 1e-6;
64 const double vpRotationMatrix::minimum = 0.00001;
66 #define vpDEBUG_LEVEL1 0
85 for (i=0 ; i < 3 ; i++)
86 for (j=0 ; j < 3; j++)
123 for (
unsigned int i=0; i<3; i++)
125 for (
unsigned int j=0; j<3; j++)
147 "m is not a rotation matrix !!!!!"));
150 for (
unsigned int i=0; i<3; i++)
152 for (
unsigned int j=0; j<3; j++)
154 (*this)[i][j] = m[i][j];
162 "m is not a rotation matrix !!!!!"));
174 for (
unsigned int i=0;i<3;i++)
175 for (
unsigned int j=0;j<3;j++)
178 for (
unsigned int k=0;k<3;k++)
202 vpERROR_TRACE(
"The matrix is not a 3 by 3 dimension matrix") ;
204 "The matrix is not a 3 by 3 dimension matrix"));
208 for (
unsigned int i=0;i<3;i++)
209 for (
unsigned int j=0;j<3;j++)
212 for (
unsigned int k=0;k<3;k++)
213 s +=(*
this)[i][k] * B[k][j];
252 vpERROR_TRACE(
"The column vector is not a 3 dimension vector") ;
254 "The column vector is not a 3 dimension vector"));
273 "Cannot add two rotation matrices !!!!!"));
285 vpERROR_TRACE(
"Cannot substract two rotation matrices !!!!! ") ;
287 "Cannot substract two rotation matrices !!!!!"));
296 for (
unsigned int j=0;j<3;j++)p[j]=0 ;
298 for (
unsigned int j=0;j<3;j++) {
299 for (
unsigned int i=0;i<3;i++) {
317 bool isRotation = true ;
321 for (i=0 ; i < 3 ; i++)
322 for (j=0 ; j < 3 ; j++)
325 if (fabs(RtR[i][j]-1) > threshold) isRotation = false ;
329 if (fabs(RtR[i][j]) > threshold) isRotation = false ;
334 for (i=0 ; i < 3 ; i++)
337 vpMath::sqr(RtR[2][i])) - 1) > threshold) isRotation = false ;
340 for (i=0 ; i < 3 ; i++)
343 vpMath::sqr(RtR[i][2])) - 1) > threshold) isRotation = false ;
441 Rt[j][i] = (*
this)[i][j];
474 for (
unsigned int i=0; i<3; i++)
476 for (
unsigned int j=0; j<3; j++)
477 std::cout << R[i][j] <<
" " ;
478 std::cout << std::endl ;
490 for (
unsigned int i=0; i<3; i++)
491 std::cout << tu[i] <<
" " ;
493 std::cout << std::endl ;
513 double theta, si, co, sinc, mcosc;
516 theta = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
522 R[0][0] = co + mcosc*v[0]*v[0];
523 R[0][1] = -sinc*v[2] + mcosc*v[0]*v[1];
524 R[0][2] = sinc*v[1] + mcosc*v[0]*v[2];
525 R[1][0] = sinc*v[2] + mcosc*v[1]*v[0];
526 R[1][1] = co + mcosc*v[1]*v[1];
527 R[1][2] = -sinc*v[0] + mcosc*v[1]*v[2];
528 R[2][0] = -sinc*v[1] + mcosc*v[2]*v[0];
529 R[2][1] = sinc*v[0] + mcosc*v[2]*v[1];
530 R[2][2] = co + mcosc*v[2]*v[2];
532 for (i=0;i<3;i++)
for (j=0;j<3;j++) (*
this)[i][j] = R[i][j];
534 #if (vpDEBUG_LEVEL1) // test new version wrt old version
538 double sinu,cosi,mcosi,u[3],ang;
540 ang = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
543 for (i=0;i<3;i++) u[i] = v[i]/ang;
547 R_old[0][0] = cosi + mcosi*u[0]*u[0];
548 R_old[0][1] = -sinu*u[2] + mcosi*u[0]*u[1];
549 R_old[0][2] = sinu*u[1] + mcosi*u[0]*u[2];
550 R_old[1][0] = sinu*u[2] + mcosi*u[1]*u[0];
551 R_old[1][1] = cosi + mcosi*u[1]*u[1];
552 R_old[1][2] = -sinu*u[0] + mcosi*u[1]*u[2];
553 R_old[2][0] = -sinu*u[1] + mcosi*u[2]*u[0];
554 R_old[2][1] = sinu*u[0] + mcosi*u[2]*u[1];
555 R_old[2][2] = cosi + mcosi*u[2]*u[2];
561 for(j=0;j<3;j++) R_old[i][j] = 0.0;
572 if (fabs(R_old[i][j] - R[i][j]) > 1.e-4) pb = 1;
576 printf(
"vpRotationMatrix::buildFrom(const vpThetaUVector &v)\n");
577 std::cout <<
" theta " << theta << std::endl;
578 std::cout <<
" R : " << std::endl << R << std::endl;
579 std::cout <<
" R_old : " << std::endl << R_old << std::endl;
595 for (
unsigned int i=0 ; i < 3 ; i++)
596 for (
unsigned int j=0 ; j < 3; j++)
597 (*
this)[i][j] = M[i][j] ;
624 double c0,c1,c2,s0,s1,s2;
633 (*this)[0][0] = c0*c1*c2 - s0*s2;
634 (*this)[0][1] = -c0*c1*s2 - s0*c2;
635 (*this)[0][2] = c0*s1;
636 (*this)[1][0] = s0*c1*c2+c0*s2 ;
637 (*this)[1][1] = -s0*c1*s2 + c0*c2 ;
638 (*this)[1][2] = s0*s1;
639 (*this)[2][0] = -s1*c2;
640 (*this)[2][1] = s1*s2;
659 double c0,c1,c2,s0,s1,s2;
668 (*this)[0][0] = c1*c2;
669 (*this)[0][1] = -c1*s2;
671 (*this)[1][0] = c0*s2+s0*s1*c2;
672 (*this)[1][1] = c0*c2-s0*s1*s2;
673 (*this)[1][2] = -s0*c1;
674 (*this)[2][0] = -c0*s1*c2+s0*s2;
675 (*this)[2][1] = c0*s1*s2+c2*s0;
676 (*this)[2][2] = c0*c1;
693 double c0,c1,c2,s0,s1,s2;
702 (*this)[0][0] = c0*c1 ;
703 (*this)[0][1] = c0*s1*s2 - s0*c2 ;
704 (*this)[0][2] = c0*s1*c2 + s0*s2 ;
706 (*this)[1][0] = s0*c1 ;
707 (*this)[1][1] = s0*s1*s2 + c0*c2 ;
708 (*this)[1][2] = s0*s1*c2 - c0*s2 ;
710 (*this)[2][0] = -s1 ;
711 (*this)[2][1] = c1*s2 ;
712 (*this)[2][2] = c1*c2 ;
738 (*this)[0][0] = a*a+b*b-c*c-d*d;
739 (*this)[0][1] = 2*b*c-2*a*d;
740 (*this)[0][2] = 2*a*c+2*b*d;
742 (*this)[1][0] = 2*a*d+2*b*c;
743 (*this)[1][1] = a*a-b*b+c*c-d*d;
744 (*this)[1][2] = 2*c*d-2*a*b;
746 (*this)[2][0] = 2*b*d-2*a*c;
747 (*this)[2][1] = 2*a*b+2*c*d;
748 (*this)[2][2] = a*a-b*b-c*c+d*d;
751 #undef vpDEBUG_LEVEL1
Definition of the vpMatrix class.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
vpRotationMatrix inverse() const
invert the rotation matrix
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
error that can be emited by ViSP classes.
double y() const
Returns y-component of the quaternion.
vpRotationMatrix t() const
transpose
Class that consider the case of the Euler angle using the z-y-x convention, where are respectively ...
void setIdentity()
Basic initialisation (identity)
vpRotationMatrix operator+(const vpRotationMatrix &B) const
overload + operator (to say it forbidden operation, throw exception)
vpRotationMatrix & operator=(const vpRotationMatrix &R)
copy operator from vpRotationMatrix
static double sinc(double x)
void init()
Basic initialisation (identity)
bool isARotationMatrix() const
test if the matrix is an rotation matrix
The vpRotationMatrix considers the particular case of a rotation matrix.
double w() const
Returns w-component of the quaternion.
double ** rowPtrs
address of the first element of each rows
static void multMatrixVector(const vpMatrix &A, const vpColVector &b, vpColVector &c)
static double mcosc(double cosx, double x)
vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M)
Build a rotation matrix from an homogeneous matrix.
static double sqr(double x)
double z() const
Returns z-component of the quaternion.
double x() const
Returns x-component of the quaternion.
Defines a quaternion and its basic operations.
void printVector()
Print the matrix as a vector [T thetaU].
vpRotationMatrix()
Default constructor.
Class that provides a data structure for the column vectors as well as a set of operations on these v...
The pose is a complete representation of every rigid motion in the euclidian space.
unsigned int getCols() const
Return the number of columns of the matrix.
vpTranslationVector operator*(const vpTranslationVector &mat) const
operation c = A * b (A is unchanged)
error that can be emited by the vpMatrix class and its derivates
Class that consider the case of the Euler angle using the x-y-z convention, where are respectively ...
vpMatrix operator-() const
Class that consider the case of the Euler angles using the z-y-z convention, where are respectively...
unsigned int getRows() const
Return the number of rows of the matrix.
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.