40#include <visp3/core/vpMath.h>
41#include <visp3/core/vpMatrix.h>
44#include <visp3/core/vpRotationMatrix.h>
47#include <visp3/core/vpException.h>
53const unsigned int vpRotationMatrix::constr_val_3 = 3;
61 const unsigned int val_3 = 3;
62 for (
unsigned int i = 0; i < val_3; ++i) {
63 for (
unsigned int j = 0; j < val_3; ++j) {
85 const unsigned int val_3 = 3;
86 for (
unsigned int i = 0; i < val_3; ++i) {
87 for (
unsigned int j = 0; j < val_3; ++j) {
88 rowPtrs[i][j] = R.rowPtrs[i][j];
95#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
125 if (
dsize !=
static_cast<unsigned int>(list.size())) {
127 "Cannot set a 3-by-3 rotation matrix from a %d-elements list of doubles."));
130 std::copy(list.begin(), list.end(),
data);
139 "Rotation matrix initialization fails since its elements do not represent a valid rotation matrix"));
165 const unsigned int val_3 = 3;
171 for (
unsigned int i = 0; i < val_3; ++i) {
172 for (
unsigned int j = 0; j < val_3; ++j) {
173 (*this)[i][j] = M[i][j];
182 "from a matrix that is not a "
264 "Cannot set rotation matrix out of bounds. It has only %d elements while you try to initialize "
279 const unsigned int val_3 = 3;
280 for (
unsigned int i = 0; i < val_3; ++i) {
281 for (
unsigned int j = 0; j < val_3; ++j) {
283 for (
unsigned int k = 0; k < val_3; ++k) {
284 s +=
rowPtrs[i][k] * R.rowPtrs[k][j];
311 const unsigned int val_3 = 3;
318 for (
unsigned int i = 0; i < val_3; ++i) {
319 for (
unsigned int j = 0; j < val_3; ++j) {
321 for (
unsigned int k = 0; k < val_3; ++k) {
322 s += (*this)[i][k] * M[k][j];
384 const unsigned int rows_size = 3;
385 if (v.getRows() != rows_size) {
387 "Cannot multiply a (3x3) rotation matrix by a %d "
388 "dimension column vector",
393 for (
unsigned int j = 0; j <
colNum; ++j) {
395 for (
unsigned int i = 0; i <
rowNum; ++i) {
396 v_out[i] +=
rowPtrs[i][j] * vj;
410 const unsigned int val_3 = 3;
412 for (
unsigned int j = 0; j < val_3; ++j) {
416 for (
unsigned int j = 0; j < val_3; ++j) {
417 for (
unsigned int i = 0; i < val_3; ++i) {
433 for (
unsigned int i = 0; i <
rowNum; ++i) {
434 for (
unsigned int j = 0; j <
colNum; ++j) {
448 for (
unsigned int i = 0; i <
rowNum; ++i) {
449 for (
unsigned int j = 0; j <
colNum; ++j) {
467 bool isRotation =
true;
468 const unsigned int val_3 = 3;
476 for (
unsigned int i = 0; i < val_3; ++i) {
477 for (
unsigned int j = 0; j < val_3; ++j) {
479 if (fabs(RtR[i][j] - 1) > threshold) {
484 if (fabs(RtR[i][j]) > threshold) {
492 const unsigned int index_2 = 2;
493 for (
unsigned int i = 0; i < val_3; ++i) {
500 for (
unsigned int i = 0; i < val_3; ++i) {
577#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
613 "Rotation matrix initialization fails since its elements do not represent a valid rotation matrix"));
629 const unsigned int val_3 = 3;
630 for (
unsigned int i = 0; i < val_3; ++i) {
631 for (
unsigned int j = 0; j < val_3; ++j) {
632 Rt[j][i] = (*this)[i][j];
683 const unsigned int val_3 = 3;
684 for (
unsigned int i = 0; i < val_3; ++i) {
685 std::cout << tu[i] <<
" ";
688 std::cout << std::endl;
702 double theta, si, co, sinc, mcosc;
705 const unsigned int index_0 = 0;
706 const unsigned int index_1 = 1;
707 const unsigned int index_2 = 2;
708 theta = sqrt((v[index_0] * v[index_0]) + (v[index_1] * v[index_1]) + (v[index_2] * v[index_2]));
714 R[index_0][index_0] = co + (mcosc * v[index_0] * v[index_0]);
715 R[index_0][index_1] = (-sinc * v[index_2]) + (mcosc * v[index_0] * v[index_1]);
716 R[index_0][index_2] = (sinc * v[index_1]) + (mcosc * v[index_0] * v[index_2]);
717 R[index_1][index_0] = (sinc * v[index_2]) + (mcosc * v[index_1] * v[index_0]);
718 R[index_1][index_1] = co + (mcosc * v[index_1] * v[index_1]);
719 R[index_1][index_2] = (-sinc * v[index_0]) + (mcosc * v[index_1] * v[index_2]);
720 R[index_2][index_0] = (-sinc * v[index_1]) + (mcosc * v[index_2] * v[index_0]);
721 R[index_2][index_1] = (sinc * v[index_0]) + (mcosc * v[index_2] * v[index_1]);
722 R[index_2][index_2] = co + (mcosc * v[index_2] * v[index_2]);
724 const unsigned int val_3 = 3;
725 for (
unsigned int i = 0; i < val_3; ++i) {
726 for (
unsigned int j = 0; j < val_3; ++j) {
727 (*this)[i][j] = R[i][j];
739 const unsigned int val_3 = 3;
740 for (
unsigned int i = 0; i < val_3; ++i) {
741 for (
unsigned int j = 0; j < val_3; ++j) {
742 (*this)[i][j] = M[i][j];
769 double c0, c1, c2, s0, s1, s2;
770 const unsigned int index_0 = 0;
771 const unsigned int index_1 = 1;
772 const unsigned int index_2 = 2;
774 c0 = cos(v[index_0]);
775 c1 = cos(v[index_1]);
776 c2 = cos(v[index_2]);
777 s0 = sin(v[index_0]);
778 s1 = sin(v[index_1]);
779 s2 = sin(v[index_2]);
781 (*this)[index_0][index_0] = (c0 * c1 * c2) - (s0 * s2);
782 (*this)[index_0][index_1] = (-c0 * c1 * s2) - (s0 * c2);
783 (*this)[index_0][index_2] = c0 * s1;
784 (*this)[index_1][index_0] = (s0 * c1 * c2) + (c0 * s2);
785 (*this)[index_1][index_1] = (-s0 * c1 * s2) + (c0 * c2);
786 (*this)[index_1][index_2] = s0 * s1;
787 (*this)[index_2][index_0] = -s1 * c2;
788 (*this)[index_2][index_1] = s1 * s2;
789 (*this)[index_2][index_2] = c1;
804 double c0, c1, c2, s0, s1, s2;
805 const unsigned int index_0 = 0;
806 const unsigned int index_1 = 1;
807 const unsigned int index_2 = 2;
809 c0 = cos(v[index_0]);
810 c1 = cos(v[index_1]);
811 c2 = cos(v[index_2]);
812 s0 = sin(v[index_0]);
813 s1 = sin(v[index_1]);
814 s2 = sin(v[index_2]);
816 (*this)[index_0][index_0] = c1 * c2;
817 (*this)[index_0][index_1] = -c1 * s2;
818 (*this)[index_0][index_2] = s1;
819 (*this)[index_1][index_0] = (c0 * s2) + (s0 * s1 * c2);
820 (*this)[index_1][index_1] = (c0 * c2) - (s0 * s1 * s2);
821 (*this)[index_1][index_2] = -s0 * c1;
822 (*this)[index_2][index_0] = (-c0 * s1 * c2) + (s0 * s2);
823 (*this)[index_2][index_1] = (c0 * s1 * s2) + (c2 * s0);
824 (*this)[index_2][index_2] = c0 * c1;
837 double c0, c1, c2, s0, s1, s2;
838 const unsigned int index_0 = 0;
839 const unsigned int index_1 = 1;
840 const unsigned int index_2 = 2;
842 c0 = cos(v[index_0]);
843 c1 = cos(v[index_1]);
844 c2 = cos(v[index_2]);
845 s0 = sin(v[index_0]);
846 s1 = sin(v[index_1]);
847 s2 = sin(v[index_2]);
849 (*this)[index_0][index_0] = c0 * c1;
850 (*this)[index_0][index_1] = (c0 * s1 * s2) - (s0 * c2);
851 (*this)[index_0][index_2] = (c0 * s1 * c2) + (s0 * s2);
853 (*this)[index_1][index_0] = s0 * c1;
854 (*this)[index_1][index_1] = (s0 * s1 * s2) + (c0 * c2);
855 (*this)[index_1][index_2] = (s0 * s1 * c2) - (c0 * s2);
857 (*this)[index_2][index_0] = -s1;
858 (*this)[index_2][index_1] = c1 * s2;
859 (*this)[index_2][index_2] = c1 * c2;
884 const unsigned int index_0 = 0;
885 const unsigned int index_1 = 1;
886 const unsigned int index_2 = 2;
887 (*this)[index_0][index_0] = (((a * a) + (b * b)) - (c * c)) - (d * d);
888 (*this)[index_0][index_1] = (2.0 * b * c) - (2.0 * a * d);
889 (*this)[index_0][index_2] = (2.0 * a * c) + (2.0 * b * d);
891 (*this)[index_1][index_0] = (2.0 * a * d) + (2.0 * b * c);
892 (*this)[index_1][index_1] = (((a * a) - (b * b)) + (c * c)) - (d * d);
893 (*this)[index_1][index_2] = (2.0 * c * d) - (2.0 * a * b);
895 (*this)[index_2][index_0] = (2.0 * b * d) - (2.0 * a * c);
896 (*this)[index_2][index_1] = (2.0 * a * b) + (2.0 * c * d);
897 (*this)[index_2][index_2] = ((a * a) - (b * b) - (c * c)) + (d * d);
948 unsigned int nb_rows =
getRows();
950 for (
unsigned int i = 0; i < nb_rows; ++i) {
951 c[i] = (*this)[i][j];
969 size_t vec_m_size = vec_M.size();
970 for (
size_t i = 0; i < vec_m_size; ++i) {
971 R = vec_M[i].getRotationMatrix();
974 meanR /=
static_cast<double>(vec_M.size());
980 const unsigned int index_0 = 0;
981 const unsigned int index_1 = 1;
982 const unsigned int index_2 = 2;
983 double det = sv[index_0] * sv[index_1] * sv[index_2];
990 D[index_0][index_0] = 1.0;
991 D[index_1][index_1] = 1.0;
992 D[index_2][index_2] = -1;
993 meanR = U * D * V.
t();
1012 size_t vec_r_size = vec_R.size();
1013 for (
size_t i = 0; i < vec_r_size; ++i) {
1014 meanR +=
static_cast<vpMatrix>(vec_R[i]);
1016 meanR /=
static_cast<double>(vec_R.size());
1022 const unsigned int index_0 = 0;
1023 const unsigned int index_1 = 1;
1024 const unsigned int index_2 = 2;
1025 double det = sv[index_0] * sv[index_1] * sv[index_2];
1032 D[index_0][index_0] = 1.0;
1033 D[index_1][index_1] = 1.0;
1034 D[index_2][index_2] = -1;
1035 meanR = U * D * V.
t();
1053 const unsigned int index_0 = 0;
1054 const unsigned int index_1 = 1;
1055 const unsigned int index_2 = 2;
1056 const unsigned int index_3 = 3;
1057 const unsigned int index_4 = 4;
1058 const unsigned int index_5 = 5;
1059 const unsigned int index_6 = 6;
1060 const unsigned int index_7 = 7;
1061 const unsigned int index_8 = 8;
1063 double det = R.det();
1065 Vt[index_2][index_0] *= -1;
1066 Vt[index_2][index_1] *= -1;
1067 Vt[index_2][index_2] *= -1;
1072 data[index_0] = R[index_0][index_0];
1073 data[index_1] = R[index_0][index_1];
1074 data[index_2] = R[index_0][index_2];
1075 data[index_3] = R[index_1][index_0];
1076 data[index_4] = R[index_1][index_1];
1077 data[index_5] = R[index_1][index_2];
1078 data[index_6] = R[index_2][index_0];
1079 data[index_7] = R[index_2][index_1];
1080 data[index_8] = R[index_2][index_2];
1083#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1103 unsigned int Rrow = R.getRows();
1104 unsigned int Rcol = R.getCols();
1106 for (
unsigned int i = 0; i < Rrow; ++i) {
1107 for (
unsigned int j = 0; j < Rcol; ++j) {
1108 C[i][j] = R[i][j] * x;
unsigned int getCols() const
unsigned int size() const
unsigned int getRows() const
Implementation of column vector and the associated operations.
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
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.
VP_DEPRECATED void setIdentity()
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.
Class that consider the case of a translation vector.