Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Euler angles parameterization for the rotation.
32  * Rzyz(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(z,psi)
33  *
34  * Authors:
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 
41 #include <visp3/core/vpRzyzVector.h>
42 #include <math.h>
43 
52  : vpRotationVector (3)
53 {}
56  : vpRotationVector(rzyz)
57 {}
58 
65 vpRzyzVector::vpRzyzVector(const double phi, const double theta, const double psi)
66  : vpRotationVector (3)
67 {
68  buildFrom(phi, theta, psi);
69 }
70 
77  : vpRotationVector (3)
78 {
79  buildFrom(R) ;
80 }
81 
89  : vpRotationVector (3)
90 {
91  buildFrom(tu) ;
92 }
93 
96  : vpRotationVector (3)
97 {
98  if (rzyz.size() != 3) {
99  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyz vector from a %d-dimension col vector", rzyz.size()));
100  }
101  for (unsigned int i=0; i< 3; i++)
102  data[i] = rzyz[i];
103 }
104 
114 {
115  double phi ;
116  if ((fabs(R[1][2]) < 1e-6) &&(fabs(R[0][2]) < 1e-6))
117  phi = 0 ;
118  else
119  phi = atan2(R[1][2],R[0][2]) ;
120  double cphi = cos(phi) ;
121  double sphi = sin(phi) ;
122 
123  double theta = atan2(cphi*R[0][2]+sphi*R[1][2],R[2][2]);
124 
125  double psi = atan2(-sphi*R[0][0]+cphi*R[1][0],-sphi*R[0][1]+cphi*R[1][1]) ;
126 
127  buildFrom(phi, theta, psi);
128 
129  return *this ;
130 }
131 
132 
142 {
143  vpRotationMatrix R ;
144  R.buildFrom(tu) ;
145  buildFrom(R) ;
146 
147  return *this ;
148 }
149 
170 {
171  for (unsigned int i=0; i< dsize; i++)
172  data[i] = v;
173 
174  return *this;
175 }
176 
183 void
184 vpRzyzVector::buildFrom(const double phi, const double theta, const double psi)
185 {
186  data[0] = phi ;
187  data[1] = theta ;
188  data[2] = psi ;
189 }
190 
214 {
215  if (rzyz.size() != 3) {
216  throw(vpException(vpException::dimensionError, "Cannot set a R-zyz vector from a %d-dimension col vector", rzyz.size()));
217  }
218  for (unsigned int i=0; i< 3; i++)
219  data[i] = rzyz[i];
220 
221  return *this;
222 }
Implementation of a generic rotation vector.
vpRzyzVector buildFrom(const vpRotationMatrix &R)
error that can be emited by ViSP classes.
Definition: vpException.h:73
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:156
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:151
Implementation of a rotation vector as axis-angle minimal representation.
vpRzyzVector & operator=(const vpColVector &rzyz)