Visual Servoing Platform  version 3.6.1 under development (2025-01-30)
vpRotationMatrix.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Rotation matrix.
32  */
33 
39 #ifndef VP_ROTATION_MATRIX_H
40 #define VP_ROTATION_MATRIX_H
41 
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpArray2D.h>
44 #include <visp3/core/vpHomogeneousMatrix.h>
45 #include <visp3/core/vpPoseVector.h>
46 #include <visp3/core/vpQuaternionVector.h>
47 #include <visp3/core/vpRxyzVector.h>
48 #include <visp3/core/vpRzyxVector.h>
49 #include <visp3/core/vpRzyzVector.h>
50 #include <visp3/core/vpThetaUVector.h>
51 #include <visp3/core/vpTranslationVector.h>
52 
53 BEGIN_VISP_NAMESPACE
129 class VISP_EXPORT vpRotationMatrix : public vpArray2D<double>
130 {
131 public:
134  VP_EXPLICIT vpRotationMatrix(const vpHomogeneousMatrix &M);
135  VP_EXPLICIT vpRotationMatrix(const vpThetaUVector &r);
136  VP_EXPLICIT vpRotationMatrix(const vpPoseVector &p);
137  VP_EXPLICIT vpRotationMatrix(const vpRzyzVector &r);
138  VP_EXPLICIT vpRotationMatrix(const vpRxyzVector &r);
139  VP_EXPLICIT vpRotationMatrix(const vpRzyxVector &r);
140  VP_EXPLICIT vpRotationMatrix(const vpQuaternionVector &q);
141  VP_EXPLICIT vpRotationMatrix(const vpMatrix &R);
142  vpRotationMatrix(double tux, double tuy, double tuz);
143 
144 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
145  VP_EXPLICIT vpRotationMatrix(const std::initializer_list<double> &list);
146 #endif
147 
148  vpRotationMatrix &buildFrom(const vpHomogeneousMatrix &M);
149  vpRotationMatrix &buildFrom(const vpThetaUVector &v);
150  vpRotationMatrix &buildFrom(const vpPoseVector &p);
151  vpRotationMatrix &buildFrom(const vpRzyzVector &v);
152  vpRotationMatrix &buildFrom(const vpRxyzVector &v);
153  vpRotationMatrix &buildFrom(const vpRzyxVector &v);
154  vpRotationMatrix &buildFrom(const vpQuaternionVector &q);
155  vpRotationMatrix &buildFrom(const double &tux, const double &tuy, const double &tuz);
156 
157  void eye();
158 
159  vpColVector getCol(unsigned int j) const;
160  vpThetaUVector getThetaUVector();
161 
162  vpRotationMatrix inverse() const;
163  void inverse(vpRotationMatrix &R) const;
164 
165  bool isARotationMatrix(double threshold = 1e-6) const;
166 
167  // copy operator from vpRotationMatrix
169  // copy operator from vpMatrix (handle with care)
171 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
172  vpRotationMatrix &operator=(const std::initializer_list<double> &list);
173 #endif
174  // operation c = A * b (A is unchanged)
176  // operation C = A * B (A is unchanged)
178  // operation C = A * B (A is unchanged)
180  vpMatrix operator*(const vpMatrix &M) const;
181  // operation v2 = A * v1 (A is unchanged)
182  vpColVector operator*(const vpColVector &v) const;
183  vpRotationMatrix operator*(double x) const;
184  vpRotationMatrix &operator*=(double x);
185 
186  vpRotationMatrix &operator<<(double val);
187  vpRotationMatrix &operator,(double val);
188 
189  void orthogonalize();
190 
191  void printVector();
192 
198  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
199  {
200  (void)nrows;
201  (void)ncols;
202  (void)flagNullify;
203  throw(vpException(vpException::fatalError, "Cannot resize a rotation matrix"));
204  }
205 
206  // transpose
207  vpRotationMatrix t() const;
208 
209  static vpRotationMatrix mean(const std::vector<vpHomogeneousMatrix> &vec_M);
210  static vpRotationMatrix mean(const std::vector<vpRotationMatrix> &vec_R);
211 
212 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
221  VP_DEPRECATED void init() { }
225  VP_DEPRECATED void setIdentity();
227 #endif
228 
229 protected:
230  unsigned int m_index;
231 private:
232  static const unsigned int constr_val_3;
233 };
234 
235 #ifndef DOXYGEN_SHOULD_SKIP_THIS
236 VISP_EXPORT
237 #endif
238 VISP_NAMESPACE_ADDRESSING vpRotationMatrix operator*(const double &x, const VISP_NAMESPACE_ADDRESSING vpRotationMatrix &R);
239 END_VISP_NAMESPACE
240 #endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition: vpArray2D.h:145
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:614
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition: vpArray2D.h:1166
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:526
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
vpColVector operator*(const double &x, const vpColVector &v)
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ fatalError
Fatal error.
Definition: vpException.h:72
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:203
Implementation of a rotation vector as quaternion angle minimal representation.
Implementation of a rotation matrix and operations on such kind of matrices.
unsigned int m_index
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:183
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRzyxVector.h:184
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRzyzVector.h:182
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.
vpMatrix operator*(const double &x, const vpMatrix &A)