Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpRzyxVector.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  * Rzyx angle parameterization for the rotation.
32  * Rzyx(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(x,psi)
33  *
34  * Authors:
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 
41 #include <visp3/core/vpRzyxVector.h>
42 #include <math.h>
52  : vpRotationVector(3)
53 {}
54 
57  : vpRotationVector(rzyx)
58 {}
59 
66 vpRzyxVector::vpRzyxVector(const double phi, const double theta, const double psi)
67  : vpRotationVector (3)
68 {
69  buildFrom(phi, theta, psi);
70 }
71 
78  : vpRotationVector (3)
79 {
80  buildFrom(R) ;
81 }
82 
90  : vpRotationVector (3)
91 {
92  buildFrom(tu) ;
93 }
94 
97  : vpRotationVector (3)
98 {
99  if (rzyx.size() != 3) {
100  throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension col vector", rzyx.size()));
101  }
102  for (unsigned int i=0; i< 3; i++)
103  data[i] = rzyx[i];
104 }
105 
118 {
119  double nx = R[0][0];
120  double ny = R[1][0];
121 
122  double phi = atan2(ny,nx) ;
123  double si = sin(phi) ;
124  double co = cos(phi) ;
125 
126  double nz = R[2][0];
127  double theta = atan2(-nz, co*nx+si*ny) ;
128 
129  double ax = R[0][2];
130  double ay = R[1][2];
131  double ox = R[0][1];
132  double oy = R[1][1];
133 
134  double psi = atan2(si*ax-co*ay,-si*ox+co*oy);
135 
136  buildFrom(phi, theta, psi);
137 
138  return *this ;
139 }
140 
141 
151 {
152  vpRotationMatrix R ;
153  R.buildFrom(tu) ;
154  buildFrom(R) ;
155 
156  return *this ;
157 }
158 
165 void
166 vpRzyxVector::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 
193 {
194  for (unsigned int i=0; i< dsize; i++)
195  data[i] = v;
196 
197  return *this;
198 }
199 
223 {
224  if (rzyx.size() != 3) {
225  throw(vpException(vpException::dimensionError, "Cannot set a R-zyx vector from a %d-dimension col vector", rzyx.size()));
226  }
227  for (unsigned int i=0; i< 3; i++)
228  data[i] = rzyx[i];
229 
230  return *this;
231 }
Implementation of a generic rotation vector.
error that can be emited by ViSP classes.
Definition: vpException.h:73
vpRzyxVector & operator=(const vpColVector &rzyx)
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 vector as Euler angle minimal representation.
Definition: vpRzyxVector.h:152
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:72
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:80
Implementation of a rotation vector as axis-angle minimal representation.