45 #include <visp3/core/vpMath.h>
46 #include <visp3/core/vpMatrix.h>
49 #include <visp3/core/vpRotationMatrix.h>
53 #include <visp3/core/vpException.h>
56 #include <visp3/core/vpDebug.h>
58 const double vpRotationMatrix::threshold = 1e-6;
79 for (
unsigned int i=0 ; i < 3 ; i++) {
80 for (
unsigned int j=0 ; j < 3; j++) {
101 for (
unsigned int i=0; i<3; i++) {
102 for (
unsigned int j=0; j<3; j++) {
130 "Cannot set a (3x3) rotation matrix from a (%dx%d) matrix",
134 for (
unsigned int i=0; i<3; i++) {
135 for (
unsigned int j=0; j<3; j++) {
136 (*this)[i][j] = M[i][j];
142 "Cannot set a rotation matrix from a matrix that is not a rotation matrix"));
156 for (
unsigned int i=0;i<3;i++) {
157 for (
unsigned int j=0;j<3;j++) {
159 for (
unsigned int k=0;k<3;k++)
185 "Cannot set a (3x3) rotation matrix from a (%dx%d) matrix",
190 for (
unsigned int i=0;i<3;i++) {
191 for (
unsigned int j=0;j<3;j++) {
193 for (
unsigned int k=0;k<3;k++)
194 s +=(*
this)[i][k] * M[k][j];
235 "Cannot multiply a (3x3) rotation matrix by a %d dimension column vector",
240 for (
unsigned int j=0;j<
colNum;j++) {
242 for (
unsigned int i=0;i<
rowNum;i++) {
243 v_out[i] +=
rowPtrs[i][j] * vj;
259 for (
unsigned int j=0;j<3;j++)
262 for (
unsigned int j=0;j<3;j++) {
263 for (
unsigned int i=0;i<3;i++) {
279 for (
unsigned int i=0;i<
rowNum;i++)
280 for(
unsigned int j=0;j<
colNum;j++)
292 for (
unsigned int i=0;i<
rowNum;i++)
293 for(
unsigned int j=0;j<
colNum;j++)
308 bool isRotation = true ;
312 for (i=0 ; i < 3 ; i++) {
313 for (j=0 ; j < 3 ; j++) {
315 if (fabs(RtR[i][j]-1) > threshold) isRotation = false ;
318 if (fabs(RtR[i][j]) > threshold) isRotation = false ;
324 for (i=0 ; i < 3 ; i++) {
327 vpMath::sqr(RtR[2][i])) - 1) > threshold) isRotation = false ;
331 for (i=0 ; i < 3 ; i++) {
334 vpMath::sqr(RtR[i][2])) - 1) > threshold) isRotation = false ;
435 Rt[j][i] = (*
this)[i][j];
483 for (
unsigned int i=0; i<3; i++)
484 std::cout << tu[i] <<
" " ;
486 std::cout << std::endl ;
502 double theta, si, co, sinc, mcosc;
505 theta = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
511 R[0][0] = co + mcosc*v[0]*v[0];
512 R[0][1] = -sinc*v[2] + mcosc*v[0]*v[1];
513 R[0][2] = sinc*v[1] + mcosc*v[0]*v[2];
514 R[1][0] = sinc*v[2] + mcosc*v[1]*v[0];
515 R[1][1] = co + mcosc*v[1]*v[1];
516 R[1][2] = -sinc*v[0] + mcosc*v[1]*v[2];
517 R[2][0] = -sinc*v[1] + mcosc*v[2]*v[0];
518 R[2][1] = sinc*v[0] + mcosc*v[2]*v[1];
519 R[2][2] = co + mcosc*v[2]*v[2];
521 for (i=0;i<3;i++)
for (j=0;j<3;j++) (*
this)[i][j] = R[i][j];
532 for (
unsigned int i=0 ; i < 3 ; i++)
533 for (
unsigned int j=0 ; j < 3; j++)
534 (*
this)[i][j] = M[i][j] ;
560 double c0,c1,c2,s0,s1,s2;
569 (*this)[0][0] = c0*c1*c2 - s0*s2;
570 (*this)[0][1] = -c0*c1*s2 - s0*c2;
571 (*this)[0][2] = c0*s1;
572 (*this)[1][0] = s0*c1*c2+c0*s2 ;
573 (*this)[1][1] = -s0*c1*s2 + c0*c2 ;
574 (*this)[1][2] = s0*s1;
575 (*this)[2][0] = -s1*c2;
576 (*this)[2][1] = s1*s2;
594 double c0,c1,c2,s0,s1,s2;
603 (*this)[0][0] = c1*c2;
604 (*this)[0][1] = -c1*s2;
606 (*this)[1][0] = c0*s2+s0*s1*c2;
607 (*this)[1][1] = c0*c2-s0*s1*s2;
608 (*this)[1][2] = -s0*c1;
609 (*this)[2][0] = -c0*s1*c2+s0*s2;
610 (*this)[2][1] = c0*s1*s2+c2*s0;
611 (*this)[2][2] = c0*c1;
627 double c0,c1,c2,s0,s1,s2;
636 (*this)[0][0] = c0*c1 ;
637 (*this)[0][1] = c0*s1*s2 - s0*c2 ;
638 (*this)[0][2] = c0*s1*c2 + s0*s2 ;
640 (*this)[1][0] = s0*c1 ;
641 (*this)[1][1] = s0*s1*s2 + c0*c2 ;
642 (*this)[1][2] = s0*s1*c2 - c0*s2 ;
644 (*this)[2][0] = -s1 ;
645 (*this)[2][1] = c1*s2 ;
646 (*this)[2][2] = c1*c2 ;
676 (*this)[0][0] = a*a+b*b-c*c-d*d;
677 (*this)[0][1] = 2*b*c-2*a*d;
678 (*this)[0][2] = 2*a*c+2*b*d;
680 (*this)[1][0] = 2*a*d+2*b*c;
681 (*this)[1][1] = a*a-b*b+c*c-d*d;
682 (*this)[1][2] = 2*c*d-2*a*b;
684 (*this)[2][0] = 2*b*d-2*a*c;
685 (*this)[2][1] = 2*a*b+2*c*d;
686 (*this)[2][2] = a*a-b*b-c*c+d*d;
697 unsigned int Rrow = R.
getRows() ;
698 unsigned int Rcol = R.
getCols() ;
700 for (
unsigned int i=0;i<Rrow;i++)
701 for(
unsigned int j=0;j<Rcol;j++)
749 "Unable to extract a column vector from the homogeneous matrix"));
750 unsigned int nb_rows =
getRows();
752 for (
unsigned int i=0 ; i < nb_rows ; i++)
753 c[i] = (*
this)[i][j];
Implementation of a matrix and operations on matrices.
vpRotationMatrix inverse() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpColVector operator*(const double &x, const vpColVector &v)
error that can be emited by ViSP classes.
double y() const
Returns y-component of the quaternion.
vpColVector getCol(const unsigned int j) const
vpRotationMatrix t() const
Implementation of a generic 2D array used as vase class of matrices and vectors.
unsigned int getCols() const
Return the number of columns of the 2D array.
Implementation of a rotation vector as Euler angle minimal representation.
vp_deprecated void setIdentity()
vpRotationMatrix & operator=(const vpRotationMatrix &R)
vpThetaUVector buildFrom(const vpHomogeneousMatrix &M)
static double sinc(double x)
bool isARotationMatrix() const
Implementation of a rotation matrix and operations on such kind of matrices.
double w() const
Returns w-component of the quaternion.
unsigned int rowNum
Number of rows in the array.
vpRotationMatrix & operator*=(const double x)
static double mcosc(double cosx, double x)
vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M)
static double sqr(double x)
double z() const
Returns z-component of the quaternion.
double x() const
Returns x-component of the quaternion.
Implementation of a rotation vector as quaternion angle minimal representation.
unsigned int getRows() const
Return the number of rows of the 2D array.
unsigned int colNum
Number of columns in the array.
vpTranslationVector operator*(const vpTranslationVector &tv) const
Implementation of column vector and the associated operations.
Implementation of a pose vector and operations on poses.
Implementation of a rotation vector as Euler angle minimal representation.
vpThetaUVector getThetaUVector()
Implementation of a rotation vector as Euler angle minimal representation.
Class that consider the case of a translation vector.
Implementation of a rotation vector as axis-angle minimal representation.
double ** rowPtrs
Address of the first element of each rows.