Visual Servoing Platform  version 3.4.0
vpRxyzVector.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  * Rxyz angle parameterization for the rotation.
33  * Rxyz(phi,theta,psi) = Rot(x,phi)Rot(y,theta)Rot(z,psi).
34  *
35  * Authors:
36  * Eric Marchand
37  * Fabien Spindler
38  *
39  *****************************************************************************/
40 
41 #include <math.h>
42 
43 #include <visp3/core/vpRxyzVector.h>
44 
53 
56 
63 vpRxyzVector::vpRxyzVector(double phi, double theta, double psi) : vpRotationVector(3)
64 {
65  buildFrom(phi, theta, psi);
66 }
67 
74 
82 
85 {
86  buildFrom(rxyz);
87 }
88 
90 vpRxyzVector::vpRxyzVector(const std::vector<double> &rxyz) : vpRotationVector(3)
91 {
92  buildFrom(rxyz);
93 }
94 
103 {
104  double COEF_MIN_ROT = 1e-6;
105  double phi;
106 
107  if ((fabs(R[1][2]) < COEF_MIN_ROT) && (fabs(R[2][2]) < COEF_MIN_ROT))
108  phi = 0;
109  else
110  phi = atan2(-R[1][2], R[2][2]);
111 
112  double si = sin(phi);
113  double co = cos(phi);
114  double theta = atan2(R[0][2], -si * R[1][2] + co * R[2][2]);
115  double psi = atan2(co * R[1][0] + si * R[2][0], co * R[1][1] + si * R[2][1]);
116 
117  buildFrom(phi, theta, psi);
118 
119  return *this;
120 }
121 
129 {
131  R.buildFrom(tu);
132  buildFrom(R);
133 
134  return *this;
135 }
136 
143 void vpRxyzVector::buildFrom(double phi, double theta, double psi)
144 {
145  data[0] = phi;
146  data[1] = theta;
147  data[2] = psi;
148 }
149 
154 {
155  if (rxyz.size() != 3) {
156  throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension col vector",
157  rxyz.size()));
158  }
159  for (unsigned int i = 0; i < 3; i++)
160  data[i] = rxyz[i];
161 
162  return *this;
163 }
164 
168 vpRxyzVector vpRxyzVector::buildFrom(const std::vector<double> &rxyz)
169 {
170  if (rxyz.size() != 3) {
171  throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension std::vector",
172  rxyz.size()));
173  }
174  for (unsigned int i = 0; i < 3; i++)
175  data[i] = rxyz[i];
176 
177  return *this;
178 }
179 
200 {
201  for (unsigned int i = 0; i < dsize; i++)
202  data[i] = v;
203 
204  return *this;
205 }
206 
231 {
232  if (rxyz.size() != 3) {
233  throw(vpException(vpException::dimensionError, "Cannot set a R-xyz vector from a %d-dimension col vector",
234  rxyz.size()));
235  }
236  for (unsigned int i = 0; i < 3; i++)
237  data[i] = rxyz[i];
238 
239  return *this;
240 }
241 
242 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
243 
260 vpRxyzVector &vpRxyzVector::operator=(const std::initializer_list<double> &list)
261 {
262  if (list.size() > size()) {
263  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()));
264  }
265  std::copy(list.begin(), list.end(), data);
266  return *this;
267 }
268 #endif
vpRxyzVector & operator=(const vpColVector &rxyz)
Implementation of a generic rotation vector.
vpRxyzVector buildFrom(const vpRotationMatrix &R)
error that can be emited by ViSP classes.
Definition: vpException.h:71
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 matrix and operations on such kind of matrices.
vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:183
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:141
Implementation of a rotation vector as axis-angle minimal representation.