Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
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 
44 BEGIN_VISP_NAMESPACE
49 
56 vpRzyzVector::vpRzyzVector(double phi, double theta, double psi) : vpRotationVector(3) { buildFrom(phi, theta, psi); }
57 
64 
72 
75 
77 vpRzyzVector::vpRzyzVector(const std::vector<double> &rzyz) : vpRotationVector(3) { buildFrom(rzyz); }
78 
87 {
88  double phi;
89  const unsigned int index_0 = 0;
90  const unsigned int index_1 = 1;
91  const unsigned int index_2 = 2;
92  if ((fabs(R[index_1][index_2]) < 1e-6) && (fabs(R[index_0][index_2]) < 1e-6)) {
93  phi = 0;
94  }
95  else {
96  phi = atan2(R[index_1][index_2], R[index_0][index_2]);
97  }
98  double cphi = cos(phi);
99  double sphi = sin(phi);
100 
101  double theta = atan2((cphi * R[index_0][index_2]) + (sphi * R[index_1][index_2]), R[index_2][index_2]);
102 
103  double psi = atan2((-sphi * R[0][0]) + (cphi * R[1][0]), (-sphi * R[0][1]) + (cphi * R[1][1]));
104 
105  buildFrom(phi, theta, psi);
106 
107  return *this;
108 }
109 
117 {
119  R.buildFrom(tu);
120  buildFrom(R);
121 
122  return *this;
123 }
124 
129 {
130  if (rzyz.size() != 3) {
131  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyz vector from a %d-dimension col vector",
132  rzyz.size()));
133  }
134  const unsigned int val_3 = 3;
135  for (unsigned int i = 0; i < val_3; ++i) {
136  data[i] = rzyz[i];
137  }
138 
139  return *this;
140 }
141 
145 vpRzyzVector &vpRzyzVector::buildFrom(const std::vector<double> &rzyz)
146 {
147  if (rzyz.size() != 3) {
148  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension std::vector",
149  rzyz.size()));
150  }
151  const unsigned int val_3 = 3;
152  for (unsigned int i = 0; i < val_3; ++i) {
153  data[i] = rzyz[i];
154  }
155 
156  return *this;
157 }
158 
165 vpRzyzVector &vpRzyzVector::buildFrom(const double &phi, const double &theta, const double &psi)
166 {
167  const unsigned int index_0 = 0;
168  const unsigned int index_1 = 1;
169  const unsigned int index_2 = 2;
170  data[index_0] = phi;
171  data[index_1] = theta;
172  data[index_2] = psi;
173  return *this;
174 }
175 
200 {
201  for (unsigned int i = 0; i < dsize; ++i) {
202  data[i] = v;
203  }
204 
205  return *this;
206 }
207 
235 {
236  if (rzyz.size() != 3) {
237  throw(vpException(vpException::dimensionError, "Cannot set a R-zyz vector from a %d-dimension col vector",
238  rzyz.size()));
239  }
240  const unsigned int val_3 = 3;
241  for (unsigned int i = 0; i < val_3; ++i) {
242  data[i] = rzyz[i];
243  }
244 
245  return *this;
246 }
247 
248 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
270 vpRzyzVector &vpRzyzVector::operator=(const std::initializer_list<double> &list)
271 {
272  if (list.size() > size()) {
273  throw(vpException(
275  "Cannot set Euler x-y-z vector out of bounds. It has only %d values while you try to initialize with %d values",
276  size(), list.size()));
277  }
278  std::copy(list.begin(), list.end(), data);
279  return *this;
280 }
281 #endif
282 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:1107
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 & buildFrom(const vpHomogeneousMatrix &M)
Implementation of a generic rotation vector.
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRzyzVector.h:182
vpRzyzVector & buildFrom(const vpRotationMatrix &R)
vpRzyzVector & operator=(const vpColVector &rzyz)
Implementation of a rotation vector as axis-angle minimal representation.