40 #include <visp3/core/vpMath.h>
41 #include <visp3/core/vpMatrix.h>
44 #include <visp3/core/vpRotationMatrix.h>
47 #include <visp3/core/vpException.h>
60 const unsigned int val_3 = 3;
61 for (
unsigned int i = 0; i < val_3; ++i) {
62 for (
unsigned int j = 0; j < val_3; ++j) {
84 const unsigned int val_3 = 3;
85 for (
unsigned int i = 0; i < val_3; ++i) {
86 for (
unsigned int j = 0; j < val_3; ++j) {
94 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
124 if (
dsize !=
static_cast<unsigned int>(list.size())) {
126 "Cannot set a 3-by-3 rotation matrix from a %d-elements list of doubles."));
129 std::copy(list.begin(), list.end(),
data);
138 "Rotation matrix initialization fails since its elements do not represent a valid rotation matrix"));
169 const unsigned int val_3 = 3;
170 for (
unsigned int i = 0; i < val_3; ++i) {
171 for (
unsigned int j = 0; j < val_3; ++j) {
172 (*this)[i][j] = M[i][j];
178 "from a matrix that is not a "
259 "Cannot set rotation matrix out of bounds. It has only %d elements while you try to initialize "
274 const unsigned int val_3 = 3;
275 for (
unsigned int i = 0; i < val_3; ++i) {
276 for (
unsigned int j = 0; j < val_3; ++j) {
278 for (
unsigned int k = 0; k < 3; ++k) {
312 const unsigned int val_3 = 3;
313 for (
unsigned int i = 0; i < val_3; ++i) {
314 for (
unsigned int j = 0; j < val_3; ++j) {
316 for (
unsigned int k = 0; k < 3; ++k) {
317 s += (*this)[i][k] * M[k][j];
379 const unsigned int rows_size = 3;
380 if (v.
getRows() != rows_size) {
382 "Cannot multiply a (3x3) rotation matrix by a %d "
383 "dimension column vector",
388 for (
unsigned int j = 0; j <
colNum; ++j) {
390 for (
unsigned int i = 0; i <
rowNum; ++i) {
391 v_out[i] +=
rowPtrs[i][j] * vj;
405 const unsigned int val_3 = 3;
407 for (
unsigned int j = 0; j < val_3; ++j) {
411 for (
unsigned int j = 0; j < val_3; ++j) {
412 for (
unsigned int i = 0; i < val_3; ++i) {
428 for (
unsigned int i = 0; i <
rowNum; ++i) {
429 for (
unsigned int j = 0; j <
colNum; ++j) {
443 for (
unsigned int i = 0; i <
rowNum; ++i) {
444 for (
unsigned int j = 0; j <
colNum; ++j) {
462 bool isRotation =
true;
470 const unsigned int val_3 = 3;
471 for (
unsigned int i = 0; i < val_3; ++i) {
472 for (
unsigned int j = 0; j < val_3; ++j) {
474 if (fabs(RtR[i][j] - 1) > threshold) {
479 if (fabs(RtR[i][j]) > threshold) {
487 const unsigned int index_2 = 2;
488 for (
unsigned int i = 0; i < val_3; ++i) {
495 for (
unsigned int i = 0; i < val_3; ++i) {
572 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
599 :
vpArray2D<double>(3, 3, list), m_index(0)
608 "Rotation matrix initialization fails since its elements do not represent a valid rotation matrix"));
624 const unsigned int val_3 = 3;
625 for (
unsigned int i = 0; i < val_3; ++i) {
626 for (
unsigned int j = 0; j < val_3; ++j) {
627 Rt[j][i] = (*this)[i][j];
678 const unsigned int val_3 = 3;
679 for (
unsigned int i = 0; i < val_3; ++i) {
680 std::cout << tu[i] <<
" ";
683 std::cout << std::endl;
697 double theta, si, co, sinc, mcosc;
700 const unsigned int index_0 = 0;
701 const unsigned int index_1 = 1;
702 const unsigned int index_2 = 2;
703 theta = sqrt((v[index_0] * v[index_0]) + (v[index_1] * v[index_1]) + (v[index_2] * v[index_2]));
709 R[index_0][index_0] = co + (mcosc * v[index_0] * v[index_0]);
710 R[index_0][index_1] = (-sinc * v[index_2]) + (mcosc * v[index_0] * v[index_1]);
711 R[index_0][index_2] = (sinc * v[index_1]) + (mcosc * v[index_0] * v[index_2]);
712 R[index_1][index_0] = (sinc * v[index_2]) + (mcosc * v[index_1] * v[index_0]);
713 R[index_1][index_1] = co + (mcosc * v[index_1] * v[index_1]);
714 R[index_1][index_2] = (-sinc * v[index_0]) + (mcosc * v[index_1] * v[index_2]);
715 R[index_2][index_0] = (-sinc * v[index_1]) + (mcosc * v[index_2] * v[index_0]);
716 R[index_2][index_1] = (sinc * v[index_0]) + (mcosc * v[index_2] * v[index_1]);
717 R[index_2][index_2] = co + (mcosc * v[index_2] * v[index_2]);
719 const unsigned int val_3 = 3;
720 for (
unsigned int i = 0; i < val_3; ++i) {
721 for (
unsigned int j = 0; j < val_3; ++j) {
722 (*this)[i][j] = R[i][j];
734 const unsigned int val_3 = 3;
735 for (
unsigned int i = 0; i < val_3; ++i) {
736 for (
unsigned int j = 0; j < val_3; ++j) {
737 (*this)[i][j] = M[i][j];
764 double c0, c1, c2, s0, s1, s2;
765 const unsigned int index_0 = 0;
766 const unsigned int index_1 = 1;
767 const unsigned int index_2 = 2;
769 c0 = cos(v[index_0]);
770 c1 = cos(v[index_1]);
771 c2 = cos(v[index_2]);
772 s0 = sin(v[index_0]);
773 s1 = sin(v[index_1]);
774 s2 = sin(v[index_2]);
776 (*this)[index_0][index_0] = (c0 * c1 * c2) - (s0 * s2);
777 (*this)[index_0][index_1] = (-c0 * c1 * s2) - (s0 * c2);
778 (*this)[index_0][index_2] = c0 * s1;
779 (*this)[index_1][index_0] = (s0 * c1 * c2) + (c0 * s2);
780 (*this)[index_1][index_1] = (-s0 * c1 * s2) + (c0 * c2);
781 (*this)[index_1][index_2] = s0 * s1;
782 (*this)[index_2][index_0] = -s1 * c2;
783 (*this)[index_2][index_1] = s1 * s2;
784 (*this)[index_2][index_2] = c1;
799 double c0, c1, c2, s0, s1, s2;
800 const unsigned int index_0 = 0;
801 const unsigned int index_1 = 1;
802 const unsigned int index_2 = 2;
804 c0 = cos(v[index_0]);
805 c1 = cos(v[index_1]);
806 c2 = cos(v[index_2]);
807 s0 = sin(v[index_0]);
808 s1 = sin(v[index_1]);
809 s2 = sin(v[index_2]);
811 (*this)[index_0][index_0] = c1 * c2;
812 (*this)[index_0][index_1] = -c1 * s2;
813 (*this)[index_0][index_2] = s1;
814 (*this)[index_1][index_0] = (c0 * s2) + (s0 * s1 * c2);
815 (*this)[index_1][index_1] = (c0 * c2) - (s0 * s1 * s2);
816 (*this)[index_1][index_2] = -s0 * c1;
817 (*this)[index_2][index_0] = (-c0 * s1 * c2) + (s0 * s2);
818 (*this)[index_2][index_1] = (c0 * s1 * s2) + (c2 * s0);
819 (*this)[index_2][index_2] = c0 * c1;
832 double c0, c1, c2, s0, s1, s2;
833 const unsigned int index_0 = 0;
834 const unsigned int index_1 = 1;
835 const unsigned int index_2 = 2;
837 c0 = cos(v[index_0]);
838 c1 = cos(v[index_1]);
839 c2 = cos(v[index_2]);
840 s0 = sin(v[index_0]);
841 s1 = sin(v[index_1]);
842 s2 = sin(v[index_2]);
844 (*this)[index_0][index_0] = c0 * c1;
845 (*this)[index_0][index_1] = (c0 * s1 * s2) - (s0 * c2);
846 (*this)[index_0][index_2] = (c0 * s1 * c2) + (s0 * s2);
848 (*this)[index_1][index_0] = s0 * c1;
849 (*this)[index_1][index_1] = (s0 * s1 * s2) + (c0 * c2);
850 (*this)[index_1][index_2] = (s0 * s1 * c2) - (c0 * s2);
852 (*this)[index_2][index_0] = -s1;
853 (*this)[index_2][index_1] = c1 * s2;
854 (*this)[index_2][index_2] = c1 * c2;
879 const unsigned int index_0 = 0;
880 const unsigned int index_1 = 1;
881 const unsigned int index_2 = 2;
882 (*this)[index_0][index_0] = (((a * a) + (b * b)) - (c * c)) - (d * d);
883 (*this)[index_0][index_1] = (2 * b * c) - (2 * a * d);
884 (*this)[index_0][index_2] = (2 * a * c) + (2 * b * d);
886 (*this)[index_1][index_0] = (2 * a * d) + (2 * b * c);
887 (*this)[index_1][index_1] = (((a * a) - (b * b)) + (c * c)) - (d * d);
888 (*this)[index_1][index_2] = (2 * c * d) - (2 * a * b);
890 (*this)[index_2][index_0] = (2 * b * d) - (2 * a * c);
891 (*this)[index_2][index_1] = (2 * a * b) + (2 * c * d);
892 (*this)[index_2][index_2] = ((a * a) - (b * b) - (c * c)) + (d * d);
943 unsigned int nb_rows =
getRows();
945 for (
unsigned int i = 0; i < nb_rows; ++i) {
946 c[i] = (*this)[i][j];
964 size_t vec_m_size = vec_M.
size();
965 for (
size_t i = 0; i < vec_m_size; ++i) {
966 R = vec_M[i].getRotationMatrix();
969 meanR /=
static_cast<double>(vec_M.size());
975 const unsigned int index_0 = 0;
976 const unsigned int index_1 = 1;
977 const unsigned int index_2 = 2;
978 double det = sv[index_0] * sv[index_1] * sv[index_2];
985 D[index_0][index_0] = 1.0;
986 D[index_1][index_1] = 1.0;
987 D[index_2][index_2] = -1;
988 meanR = U * D * V.
t();
1007 size_t vec_r_size = vec_R.
size();
1008 for (
size_t i = 0; i < vec_r_size; ++i) {
1011 meanR /=
static_cast<double>(vec_R.size());
1017 const unsigned int index_0 = 0;
1018 const unsigned int index_1 = 1;
1019 const unsigned int index_2 = 2;
1020 double det = sv[index_0] * sv[index_1] * sv[index_2];
1027 D[index_0][index_0] = 1.0;
1028 D[index_1][index_1] = 1.0;
1029 D[index_2][index_2] = -1;
1030 meanR = U * D * V.
t();
1048 const unsigned int index_0 = 0;
1049 const unsigned int index_1 = 1;
1050 const unsigned int index_2 = 2;
1051 const unsigned int index_3 = 3;
1052 const unsigned int index_4 = 4;
1053 const unsigned int index_5 = 5;
1054 const unsigned int index_6 = 6;
1055 const unsigned int index_7 = 7;
1056 const unsigned int index_8 = 8;
1058 double det = R.
det();
1060 Vt[index_2][index_0] *= -1;
1061 Vt[index_2][index_1] *= -1;
1062 Vt[index_2][index_2] *= -1;
1067 data[index_0] = R[index_0][index_0];
1068 data[index_1] = R[index_0][index_1];
1069 data[index_2] = R[index_0][index_2];
1070 data[index_3] = R[index_1][index_0];
1071 data[index_4] = R[index_1][index_1];
1072 data[index_5] = R[index_1][index_2];
1073 data[index_6] = R[index_2][index_0];
1074 data[index_7] = R[index_2][index_1];
1075 data[index_8] = R[index_2][index_2];
1078 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1087 void vpRotationMatrix::setIdentity() {
eye(); }
1098 unsigned int Rrow = R.
getRows();
1099 unsigned int Rcol = R.
getCols();
1101 for (
unsigned int i = 0; i < Rrow; ++i) {
1102 for (
unsigned int j = 0; j < Rcol; ++j) {
1103 C[i][j] = R[i][j] * x;
Implementation of a generic 2D array used as base class for matrices and vectors.
unsigned int getCols() const
double * data
Address of the first element of the data array.
double ** rowPtrs
Address of the first element of each rows.
unsigned int rowNum
Number of rows in the array.
unsigned int dsize
Current array size (rowNum * colNum)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
unsigned int colNum
Number of columns in the array.
Implementation of column vector and the associated operations.
vpColVector operator*(const double &x, const vpColVector &v)
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpRotationMatrix getRotationMatrix() const
vpTranslationVector getTranslationVector() const
static double sinc(double x)
static double sqr(double x)
static double mcosc(double cosx, double x)
Implementation of a matrix and operations on matrices.
void svd(vpColVector &w, vpMatrix &V)
vpMatrix pseudoInverse(double svThreshold=1e-6) const
double det(vpDetMethod method=LU_DECOMPOSITION) const
Implementation of a pose vector and operations on poses.
Implementation of a rotation vector as quaternion angle minimal representation.
const double & z() const
Returns the z-component of the quaternion.
const double & x() const
Returns the x-component of the quaternion.
const double & y() const
Returns the y-component of the quaternion.
const double & w() const
Returns the w-component of the quaternion.
Implementation of a rotation matrix and operations on such kind of matrices.
vpRotationMatrix & operator*=(double x)
bool isARotationMatrix(double threshold=1e-6) const
vpRotationMatrix & operator,(double val)
vpColVector getCol(unsigned int j) const
vpThetaUVector getThetaUVector()
vpRotationMatrix & operator<<(double val)
vpRotationMatrix & buildFrom(const vpHomogeneousMatrix &M)
vpRotationMatrix t() const
vpRotationMatrix inverse() const
vpTranslationVector operator*(const vpTranslationVector &tv) const
static vpRotationMatrix mean(const std::vector< vpHomogeneousMatrix > &vec_M)
vpRotationMatrix & operator=(const vpRotationMatrix &R)
Implementation of a rotation vector as Euler angle minimal representation.
Implementation of a rotation vector as Euler angle minimal representation.
Implementation of a rotation vector as Euler angle minimal representation.
Implementation of a rotation vector as axis-angle minimal representation.
vpThetaUVector & buildFrom(const vpHomogeneousMatrix &M)
Class that consider the case of a translation vector.