Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
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 
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 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
149  VP_DEPRECATED vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M);
150  VP_DEPRECATED vpRotationMatrix buildFrom(const vpThetaUVector &v);
151  VP_DEPRECATED vpRotationMatrix buildFrom(const vpPoseVector &p);
152  VP_DEPRECATED vpRotationMatrix buildFrom(const vpRzyzVector &v);
153  VP_DEPRECATED vpRotationMatrix buildFrom(const vpRxyzVector &v);
154  VP_DEPRECATED vpRotationMatrix buildFrom(const vpRzyxVector &v);
155  VP_DEPRECATED vpRotationMatrix buildFrom(const vpQuaternionVector &q);
156  VP_DEPRECATED vpRotationMatrix buildFrom(double tux, double tuy, double tuz);
157 #endif
158  vpRotationMatrix &build(const vpHomogeneousMatrix &M);
159  vpRotationMatrix &build(const vpThetaUVector &v);
160  vpRotationMatrix &build(const vpPoseVector &p);
161  vpRotationMatrix &build(const vpRzyzVector &v);
162  vpRotationMatrix &build(const vpRxyzVector &v);
163  vpRotationMatrix &build(const vpRzyxVector &v);
164  vpRotationMatrix &build(const vpQuaternionVector &q);
165  vpRotationMatrix &build(const double &tux, const double &tuy, const double &tuz);
166 
167  void eye();
168 
169  vpColVector getCol(unsigned int j) const;
170  vpThetaUVector getThetaUVector();
171 
172  vpRotationMatrix inverse() const;
173  void inverse(vpRotationMatrix &R) const;
174 
175  bool isARotationMatrix(double threshold = 1e-6) const;
176 
177  // copy operator from vpRotationMatrix
179  // copy operator from vpMatrix (handle with care)
181 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
182  vpRotationMatrix &operator=(const std::initializer_list<double> &list);
183 #endif
184  // operation c = A * b (A is unchanged)
186  // operation C = A * B (A is unchanged)
188  // operation C = A * B (A is unchanged)
190  vpMatrix operator*(const vpMatrix &M) const;
191  // operation v2 = A * v1 (A is unchanged)
192  vpColVector operator*(const vpColVector &v) const;
193  vpRotationMatrix operator*(double x) const;
194  vpRotationMatrix &operator*=(double x);
195 
196  vpRotationMatrix &operator<<(double val);
197  vpRotationMatrix &operator,(double val);
198 
199  void orthogonalize();
200 
201  void printVector();
202 
208  void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
209  {
210  (void)nrows;
211  (void)ncols;
212  (void)flagNullify;
213  throw(vpException(vpException::fatalError, "Cannot resize a rotation matrix"));
214  }
215 
216  // transpose
217  vpRotationMatrix t() const;
218 
219  static vpRotationMatrix mean(const std::vector<vpHomogeneousMatrix> &vec_M);
220  static vpRotationMatrix mean(const std::vector<vpRotationMatrix> &vec_R);
221 
222 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
231  VP_DEPRECATED void init() { }
235  VP_DEPRECATED void setIdentity();
237 #endif
238 
239 protected:
240  unsigned int m_index;
241 };
242 
243 #ifndef DOXYGEN_SHOULD_SKIP_THIS
244 VISP_EXPORT
245 #endif
246 VISP_NAMESPACE_ADDRESSING vpRotationMatrix operator*(const double &x, const VISP_NAMESPACE_ADDRESSING vpRotationMatrix &R);
247 END_VISP_NAMESPACE
248 #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:611
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition: vpArray2D.h:1163
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:523
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.
VP_DEPRECATED void init()
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)