Visual Servoing Platform  version 3.6.1 under development (2024-05-26)
vpRzyzVector.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Euler angles parameterization for the rotation.
33  * Rzyz(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(z,psi)
34  */
35 
36 #include <math.h>
37 #include <visp3/core/vpRzyzVector.h>
38 
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  if ((fabs(R[1][2]) < 1e-6) && (fabs(R[0][2]) < 1e-6)) {
151  phi = 0;
152  }
153  else {
154  phi = atan2(R[1][2], R[0][2]);
155  }
156  double cphi = cos(phi);
157  double sphi = sin(phi);
158 
159  double theta = atan2((cphi * R[0][2]) + (sphi * R[1][2]), R[2][2]);
160 
161  double psi = atan2((-sphi * R[0][0]) + (cphi * R[1][0]), (-sphi * R[0][1]) + (cphi * R[1][1]));
162 
163  build(phi, theta, psi);
164 
165  return *this;
166 }
167 
175 {
177  R.build(tu);
178  build(R);
179 
180  return *this;
181 }
182 
187 {
188  if (rzyz.size() != 3) {
189  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyz vector from a %d-dimension col vector",
190  rzyz.size()));
191  }
192  for (unsigned int i = 0; i < 3; ++i) {
193  data[i] = rzyz[i];
194  }
195 
196  return *this;
197 }
198 
202 vpRzyzVector &vpRzyzVector::build(const std::vector<double> &rzyz)
203 {
204  if (rzyz.size() != 3) {
205  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension std::vector",
206  rzyz.size()));
207  }
208  for (unsigned int i = 0; i < 3; ++i) {
209  data[i] = rzyz[i];
210  }
211 
212  return *this;
213 }
214 
221 vpRzyzVector &vpRzyzVector::build(const double &phi, const double &theta, const double &psi)
222 {
223  data[0] = phi;
224  data[1] = theta;
225  data[2] = psi;
226  return *this;
227 }
228 
249 {
250  for (unsigned int i = 0; i < dsize; ++i) {
251  data[i] = v;
252  }
253 
254  return *this;
255 }
256 
280 {
281  if (rzyz.size() != 3) {
282  throw(vpException(vpException::dimensionError, "Cannot set a R-zyz vector from a %d-dimension col vector",
283  rzyz.size()));
284  }
285  for (unsigned int i = 0; i < 3; ++i) {
286  data[i] = rzyz[i];
287  }
288 
289  return *this;
290 }
291 
292 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
310 vpRzyzVector &vpRzyzVector::operator=(const std::initializer_list<double> &list)
311 {
312  if (list.size() > size()) {
313  throw(vpException(
315  "Cannot set Euler x-y-z vector out of bounds. It has only %d values while you try to initialize with %d values",
316  size(), list.size()));
317  }
318  std::copy(list.begin(), list.end(), data);
319  return *this;
320 }
321 #endif
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:139
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:135
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:341
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
error that can be emitted by ViSP classes.
Definition: vpException.h:59
@ dimensionError
Bad dimension.
Definition: vpException.h:70
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:176
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.