Visual Servoing Platform  version 3.1.0
vpRzyzVector.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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  * Euler angles parameterization for the rotation.
33  * Rzyz(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(z,psi)
34  *
35  * Authors:
36  * Eric Marchand
37  * Fabien Spindler
38  *
39  *****************************************************************************/
40 
41 #include <math.h>
42 #include <visp3/core/vpRzyzVector.h>
43 
54 
61 vpRzyzVector::vpRzyzVector(const double phi, const double theta, const double psi) : vpRotationVector(3)
62 {
63  buildFrom(phi, theta, psi);
64 }
65 
72 
80 
83 {
84  if (rzyz.size() != 3) {
85  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyz vector from a %d-dimension col vector",
86  rzyz.size()));
87  }
88  for (unsigned int i = 0; i < 3; i++)
89  data[i] = rzyz[i];
90 }
91 
100 {
101  double phi;
102  if ((fabs(R[1][2]) < 1e-6) && (fabs(R[0][2]) < 1e-6))
103  phi = 0;
104  else
105  phi = atan2(R[1][2], R[0][2]);
106  double cphi = cos(phi);
107  double sphi = sin(phi);
108 
109  double theta = atan2(cphi * R[0][2] + sphi * R[1][2], R[2][2]);
110 
111  double psi = atan2(-sphi * R[0][0] + cphi * R[1][0], -sphi * R[0][1] + cphi * R[1][1]);
112 
113  buildFrom(phi, theta, psi);
114 
115  return *this;
116 }
117 
125 {
127  R.buildFrom(tu);
128  buildFrom(R);
129 
130  return *this;
131 }
132 
153 {
154  for (unsigned int i = 0; i < dsize; i++)
155  data[i] = v;
156 
157  return *this;
158 }
159 
166 void vpRzyzVector::buildFrom(const double phi, const double theta, const double psi)
167 {
168  data[0] = phi;
169  data[1] = theta;
170  data[2] = psi;
171 }
172 
197 {
198  if (rzyz.size() != 3) {
199  throw(vpException(vpException::dimensionError, "Cannot set a R-zyz vector from a %d-dimension col vector",
200  rzyz.size()));
201  }
202  for (unsigned int i = 0; i < 3; i++)
203  data[i] = rzyz[i];
204 
205  return *this;
206 }
Implementation of a generic rotation vector.
vpRzyzVector 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:84
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:158
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:72
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:80
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRzyzVector.h:154
Implementation of a rotation vector as axis-angle minimal representation.
vpRzyzVector & operator=(const vpColVector &rzyz)