Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpRxyzVector.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  * Rxyz angle parameterization for the rotation.
32  * Rxyz(phi,theta,psi) = Rot(x,phi)Rot(y,theta)Rot(z,psi).
33  *
34  * Authors:
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 #include <math.h>
41 
42 #include <visp3/core/vpRxyzVector.h>
43 
52  : vpRotationVector(3)
53 {}
54 
57  : vpRotationVector(rxyz)
58 {}
59 
66 vpRxyzVector::vpRxyzVector(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 (rxyz.size() != 3) {
100  throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension col vector", rxyz.size()));
101  }
102  for (unsigned int i=0; i< 3; i++)
103  data[i] = rxyz[i];
104 }
105 
115 {
116  double COEF_MIN_ROT = 1e-6;
117  double phi ;
118 
119  if ((fabs(R[1][2]) < COEF_MIN_ROT) && (fabs(R[2][2]) < COEF_MIN_ROT)) phi = 0 ;
120  else phi = atan2(-R[1][2], R[2][2]) ;
121 
122  double si = sin(phi) ;
123  double co = cos(phi) ;
124  double theta = atan2(R[0][2], -si*R[1][2] + co*R[2][2]) ;
125  double psi = atan2(co*R[1][0] + si*R[2][0], co*R[1][1] + si*R[2][1]);
126 
127  buildFrom(phi, theta, psi);
128 
129  return *this ;
130 }
131 
141 {
142  vpRotationMatrix R ;
143  R.buildFrom(tu) ;
144  buildFrom(R) ;
145 
146  return *this ;
147 }
148 
155 void
156 vpRxyzVector::buildFrom(const double phi, const double theta, const double psi)
157 {
158  data[0] = phi ;
159  data[1] = theta ;
160  data[2] = psi ;
161 }
162 
183 {
184  for (unsigned int i=0; i< dsize; i++)
185  data[i] = v;
186 
187  return *this;
188 }
189 
213 {
214  if (rxyz.size() != 3) {
215  throw(vpException(vpException::dimensionError, "Cannot set a R-xyz vector from a %d-dimension col vector", rxyz.size()));
216  }
217  for (unsigned int i=0; i< 3; i++)
218  data[i] = rxyz[i];
219 
220  return *this;
221 }
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: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
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:154
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:80
Implementation of a rotation vector as axis-angle minimal representation.