Visual Servoing Platform  version 3.6.1 under development (2024-04-26)
vpRxyzVector.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  * Rxyz angle parameterization for the rotation.
33  * Rxyz(phi,theta,psi) = Rot(x,phi)Rot(y,theta)Rot(z,psi).
34  */
35 
36 #include <math.h>
37 
38 #include <visp3/core/vpRxyzVector.h>
39 
48 
51 
58 vpRxyzVector::vpRxyzVector(double phi, double theta, double psi) : vpRotationVector(3) { buildFrom(phi, theta, psi); }
59 
66 
74 
77 
79 vpRxyzVector::vpRxyzVector(const std::vector<double> &rxyz) : vpRotationVector(3) { buildFrom(rxyz); }
80 
89 {
90  double COEF_MIN_ROT = 1e-6;
91  double phi;
92 
93  if ((fabs(R[1][2]) < COEF_MIN_ROT) && (fabs(R[2][2]) < COEF_MIN_ROT)) {
94  phi = 0;
95  }
96  else {
97  phi = atan2(-R[1][2], R[2][2]);
98  }
99 
100  double si = sin(phi);
101  double co = cos(phi);
102  double theta = atan2(R[0][2], (-si * R[1][2]) + (co * R[2][2]));
103  double psi = atan2((co * R[1][0]) + (si * R[2][0]), (co * R[1][1]) + (si * R[2][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 
131 void vpRxyzVector::buildFrom(double phi, double theta, double psi)
132 {
133  data[0] = phi;
134  data[1] = theta;
135  data[2] = psi;
136 }
137 
142 {
143  if (rxyz.size() != 3) {
144  throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension col vector",
145  rxyz.size()));
146  }
147  for (unsigned int i = 0; i < 3; ++i) {
148  data[i] = rxyz[i];
149  }
150 
151  return *this;
152 }
153 
157 vpRxyzVector vpRxyzVector::buildFrom(const std::vector<double> &rxyz)
158 {
159  if (rxyz.size() != 3) {
160  throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension std::vector",
161  rxyz.size()));
162  }
163  for (unsigned int i = 0; i < 3; ++i) {
164  data[i] = rxyz[i];
165  }
166 
167  return *this;
168 }
169 
190 {
191  for (unsigned int i = 0; i < dsize; ++i) {
192  data[i] = v;
193  }
194 
195  return *this;
196 }
197 
221 {
222  if (rxyz.size() != 3) {
223  throw(vpException(vpException::dimensionError, "Cannot set a R-xyz vector from a %d-dimension col vector",
224  rxyz.size()));
225  }
226  for (unsigned int i = 0; i < 3; ++i) {
227  data[i] = rxyz[i];
228  }
229 
230  return *this;
231 }
232 
233 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
251 vpRxyzVector &vpRxyzVector::operator=(const std::initializer_list<double> &list)
252 {
253  if (list.size() > size()) {
254  throw(vpException(
256  "Cannot set Euler x-y-z vector out of bounds. It has only %d values while you try to initialize with %d values",
257  size(), list.size()));
258  }
259  std::copy(list.begin(), list.end(), data);
260  return *this;
261 }
262 #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:339
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:83
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: vpRxyzVector.h:176
vpRxyzVector buildFrom(const vpRotationMatrix &R)
vpRxyzVector & operator=(const vpColVector &rxyz)
Implementation of a rotation vector as axis-angle minimal representation.