Visual Servoing Platform  version 3.0.0
vpRxyzVector.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 
104 {
105  double COEF_MIN_ROT = 1e-6;
106  double phi ;
107 
108  if ((fabs(R[1][2]) < COEF_MIN_ROT) && (fabs(R[2][2]) < COEF_MIN_ROT)) phi = 0 ;
109  else phi = atan2(-R[1][2], R[2][2]) ;
110 
111  double si = sin(phi) ;
112  double co = cos(phi) ;
113  double theta = atan2(R[0][2], -si*R[1][2] + co*R[2][2]) ;
114  double psi = atan2(co*R[1][0] + si*R[2][0], co*R[1][1] + si*R[2][1]);
115 
116  buildFrom(phi, theta, psi);
117 
118  return *this ;
119 }
120 
130 {
131  vpRotationMatrix R ;
132  R.buildFrom(tu) ;
133  buildFrom(R) ;
134 
135  return *this ;
136 }
137 
144 void
145 vpRxyzVector::buildFrom(const double phi, const double theta, const double psi)
146 {
147  data[0] = phi ;
148  data[1] = theta ;
149  data[2] = psi ;
150 }
151 
172 {
173  for (unsigned int i=0; i< dsize; i++)
174  data[i] = v;
175 
176  return *this;
177 }
Implementation of a generic rotation vector.
vpRxyzVector buildFrom(const vpRotationMatrix &R)
vpRxyzVector & operator=(double x)
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:84
Implementation of a rotation matrix and operations on such kind of matrices.
vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M)
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.