Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpRzyzVector.cpp
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  * Euler angles parameterization for the rotation.
32  * Rzyz(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(z,psi)
33  */
34 
41 #include <math.h>
42 #include <visp3/core/vpRzyzVector.h>
43 
49 
56 vpRzyzVector::vpRzyzVector(double phi, double theta, double psi) : vpRotationVector(3) { build(phi, theta, psi); }
57 
64 
72 
75 
77 vpRzyzVector::vpRzyzVector(const std::vector<double> &rzyz) : vpRotationVector(3) { build(rzyz); }
78 
79 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
89 {
90  build(R);
91  return *this;
92 }
93 
102 {
103  build(tu);
104  return *this;
105 }
106 
112 {
113  build(rzyz);
114  return *this;
115 }
116 
121 vpRzyzVector vpRzyzVector::buildFrom(const std::vector<double> &rzyz)
122 {
123  build(rzyz);
124  return *this;
125 }
126 
134 void vpRzyzVector::buildFrom(double phi, double theta, double psi)
135 {
136  build(phi, theta, psi);
137 }
138 #endif
139 
148 {
149  double phi;
150  const unsigned int index_0 = 0;
151  const unsigned int index_1 = 1;
152  const unsigned int index_2 = 2;
153  if ((fabs(R[index_1][index_2]) < 1e-6) && (fabs(R[index_0][index_2]) < 1e-6)) {
154  phi = 0;
155  }
156  else {
157  phi = atan2(R[index_1][index_2], R[index_0][index_2]);
158  }
159  double cphi = cos(phi);
160  double sphi = sin(phi);
161 
162  double theta = atan2((cphi * R[index_0][index_2]) + (sphi * R[index_1][index_2]), R[index_2][index_2]);
163 
164  double psi = atan2((-sphi * R[0][0]) + (cphi * R[1][0]), (-sphi * R[0][1]) + (cphi * R[1][1]));
165 
166  build(phi, theta, psi);
167 
168  return *this;
169 }
170 
178 {
180  R.build(tu);
181  build(R);
182 
183  return *this;
184 }
185 
190 {
191  if (rzyz.size() != 3) {
192  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyz vector from a %d-dimension col vector",
193  rzyz.size()));
194  }
195  const unsigned int val_3 = 3;
196  for (unsigned int i = 0; i < val_3; ++i) {
197  data[i] = rzyz[i];
198  }
199 
200  return *this;
201 }
202 
206 vpRzyzVector &vpRzyzVector::build(const std::vector<double> &rzyz)
207 {
208  if (rzyz.size() != 3) {
209  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension std::vector",
210  rzyz.size()));
211  }
212  const unsigned int val_3 = 3;
213  for (unsigned int i = 0; i < val_3; ++i) {
214  data[i] = rzyz[i];
215  }
216 
217  return *this;
218 }
219 
226 vpRzyzVector &vpRzyzVector::build(const double &phi, const double &theta, const double &psi)
227 {
228  const unsigned int index_0 = 0;
229  const unsigned int index_1 = 1;
230  const unsigned int index_2 = 2;
231  data[index_0] = phi;
232  data[index_1] = theta;
233  data[index_2] = psi;
234  return *this;
235 }
236 
261 {
262  for (unsigned int i = 0; i < dsize; ++i) {
263  data[i] = v;
264  }
265 
266  return *this;
267 }
268 
296 {
297  if (rzyz.size() != 3) {
298  throw(vpException(vpException::dimensionError, "Cannot set a R-zyz vector from a %d-dimension col vector",
299  rzyz.size()));
300  }
301  const unsigned int val_3 = 3;
302  for (unsigned int i = 0; i < val_3; ++i) {
303  data[i] = rzyz[i];
304  }
305 
306  return *this;
307 }
308 
309 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
331 vpRzyzVector &vpRzyzVector::operator=(const std::initializer_list<double> &list)
332 {
333  if (list.size() > size()) {
334  throw(vpException(
336  "Cannot set Euler x-y-z vector out of bounds. It has only %d values while you try to initialize with %d values",
337  size(), list.size()));
338  }
339  std::copy(list.begin(), list.end(), data);
340  return *this;
341 }
342 #endif
343 END_VISP_NAMESPACE
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:148
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:1104
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:349
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ dimensionError
Bad dimension.
Definition: vpException.h:71
Implementation of a rotation matrix and operations on such kind of matrices.
vpRotationMatrix & build(const vpHomogeneousMatrix &M)
Implementation of a generic rotation vector.
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRzyzVector.h:182
vpRzyzVector & build(const vpRotationMatrix &R)
VP_DEPRECATED vpRzyzVector buildFrom(const vpRotationMatrix &R)
vpRzyzVector & operator=(const vpColVector &rzyz)
Implementation of a rotation vector as axis-angle minimal representation.