Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpRzyxVector.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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  * Rzyx angle parameterization for the rotation.
33  * Rzyx(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(x,psi)
34  *
35  * Authors:
36  * Eric Marchand
37  * Fabien Spindler
38  *
39  *****************************************************************************/
40 
41 #include <math.h>
42 #include <visp3/core/vpRzyxVector.h>
52 
55 
62 vpRzyxVector::vpRzyxVector(double phi, double theta, double psi) : vpRotationVector(3)
63 {
64  buildFrom(phi, theta, psi);
65 }
66 
73 
81 
84 {
85  buildFrom(rzyx);
86 }
87 
89 vpRzyxVector::vpRzyxVector(const std::vector<double> &rzyx) : vpRotationVector(3)
90 {
91  buildFrom(rzyx);
92 }
93 
105 {
106  double nx = R[0][0];
107  double ny = R[1][0];
108 
109  double phi = atan2(ny, nx);
110  double si = sin(phi);
111  double co = cos(phi);
112 
113  double nz = R[2][0];
114  double theta = atan2(-nz, co * nx + si * ny);
115 
116  double ax = R[0][2];
117  double ay = R[1][2];
118  double ox = R[0][1];
119  double oy = R[1][1];
120 
121  double psi = atan2(si * ax - co * ay, -si * ox + co * oy);
122 
123  buildFrom(phi, theta, psi);
124 
125  return *this;
126 }
127 
135 {
137  R.buildFrom(tu);
138  buildFrom(R);
139 
140  return *this;
141 }
142 
149 void vpRzyxVector::buildFrom(double phi, double theta, double psi)
150 {
151  data[0] = phi;
152  data[1] = theta;
153  data[2] = psi;
154 }
155 
160 {
161  if (rzyx.size() != 3) {
162  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension col vector",
163  rzyx.size()));
164  }
165  for (unsigned int i = 0; i < 3; i++)
166  data[i] = rzyx[i];
167 
168 
169  return *this;
170 }
171 
175 vpRzyxVector vpRzyxVector::buildFrom(const std::vector<double> &rzyx)
176 {
177  if (rzyx.size() != 3) {
178  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension std::vector",
179  rzyx.size()));
180  }
181  for (unsigned int i = 0; i < 3; i++)
182  data[i] = rzyx[i];
183 
184  return *this;
185 }
186 
207 {
208  for (unsigned int i = 0; i < dsize; i++)
209  data[i] = v;
210 
211  return *this;
212 }
213 
238 {
239  if (rzyx.size() != 3) {
240  throw(vpException(vpException::dimensionError, "Cannot set a R-zyx vector from a %d-dimension col vector",
241  rzyx.size()));
242  }
243  for (unsigned int i = 0; i < 3; i++)
244  data[i] = rzyx[i];
245 
246  return *this;
247 }
248 
249 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
250 
267 vpRzyxVector &vpRzyxVector::operator=(const std::initializer_list<double> &list)
268 {
269  if (list.size() > size()) {
270  throw(vpException(vpException::dimensionError, "Cannot set Euler x-y-z vector out of bounds. It has only %d values while you try to initialize with %d values", size(), list.size()));
271  }
272  std::copy(list.begin(), list.end(), data);
273  return *this;
274 }
275 #endif
Implementation of a generic rotation vector.
error that can be emited by ViSP classes.
Definition: vpException.h:71
vpRzyxVector & operator=(const vpColVector &rzyx)
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:145
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:291
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRzyxVector.h:185
Implementation of a rotation matrix and operations on such kind of matrices.
vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M)
vpRzyxVector buildFrom(const vpRotationMatrix &R)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:141
Implementation of a rotation vector as axis-angle minimal representation.