ViSP  2.7.0
vpRxyzVector.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRxyzVector.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Rxyz angle parameterization for the rotation.
36  * Rxyz(phi,theta,psi) = Rot(x,phi)Rot(y,theta)Rot(z,psi).
37  *
38  * Authors:
39  * Eric Marchand
40  * Fabien Spindler
41  *
42  *****************************************************************************/
43 
44 
45 #include <visp/vpRxyzVector.h>
46 #include <math.h>
59 {
60 
61  for (int i=0; i<3; i++)
62  {
63  r[i] = m.r[i] ;
64  }
65  return *this;
66 }
67 
68 
71 {
72  *this = m ;
73 }
74 
81 {
82  buildFrom(R) ;
83 }
84 
92 {
93  buildFrom(tu) ;
94 }
95 
105 {
106 
107  double COEF_MIN_ROT = 1e-6;
108  double phi ;
109 
110  if ((fabs(R[1][2]) < COEF_MIN_ROT) && (fabs(R[2][2]) < COEF_MIN_ROT)) phi = 0 ;
111  else phi = atan2(-R[1][2], R[2][2]) ;
112 
113  double si = sin(phi) ;
114  double co = cos(phi) ;
115  double theta = atan2(R[0][2], -si*R[1][2] + co*R[2][2]) ;
116  double psi = atan2(co*R[1][0] + si*R[2][0], co*R[1][1] + si*R[2][1]);
117 
118  r[0] = phi ;
119  r[1] = theta ;
120  r[2] = psi ;
121 
122  if (0) // test new version wrt old version
123  {
124  // old version
125 
126  double v1;
127  double r2[3]; // has to be replaced by r below if good version
128 
129  v1 = R[0][2];
130  if (v1 > 1.0 ) v1 = 1.0;
131  if (v1 < -1.0 ) v1 = -1.0;
132  r2[1] = asin(v1);
133  if ( fabs(fabs(r2[1]) - M_PI_2) < 0.00001)
134  {
135  r2[0] = 0.0;
136  r2[2] = atan2(R[1][0],R[1][1]);
137  }
138  else
139  {
140  r2[0] = atan2(-R[1][2],R[2][2]);
141  r2[2] = atan2(-R[0][1],R[0][0]);
142  }
143  // verification of the new version
144  int pb = 0;
145  int i;
146  for (i=0;i<3;i++)
147  {
148  if (fabs(r[i] - r2[i]) > 1e-5) pb = 1;
149  }
150  if (pb == 1)
151  {
152  printf("vpRxyzVector::buildFrom(const vpRotationMatrix& R)\n");
153  printf(" r : %lf %lf %lf\n",r[0],r[1],r[2]);
154  printf(" r2 : %lf %lf %lf\n",r2[0],r2[1],r2[2]);
155  printf(" r - r2 : %lf %lf %lf\n",r[0]-r2[0],r[1]-r2[1],r[2]-r2[2]);
156  }
157  }
158 
159  // What is below corresponds to another representation, but which one???
160  /* double phi ;
161  if ((fabs(R[1][2]) < 1e-6)&&(fabs(R[2][2]) < 1e-6)) phi = 0 ;
162  else phi = atan2(R[1][2], R[2][2]) ;
163 
164  double si = sin(phi) ;
165  double co = cos(phi) ;
166  double theta = atan2(R[0][2], -si*R[1][2] + co*R[2][2]) ;
167  double psi = atan2(co*R[0][1]+si*R[0][2], co*R[1][1]+si*R[1][2]);
168 
169  r[0] = phi ;
170  r[1] = theta ;
171  r[2] = psi ;*/
172 
173  return *this ;
174 }
175 
185 {
186  vpRotationMatrix R ;
187  R.buildFrom(tu) ;
188  buildFrom(R) ;
189 
190  return *this ;
191 }
192 
193 /*
194  * Local variables:
195  * c-basic-offset: 2
196  * End:
197  */
Class that consider the case of a generic rotation vector (cannot be used as is !) consisting in thre...
vpRxyzVector()
Default constructor. Initialize the angles to zero.
Definition: vpRxyzVector.h:159
The vpRotationMatrix considers the particular case of a rotation matrix.
vpRotationMatrix buildFrom(const vpThetaUVector &v)
Transform a vector vpThetaUVector into an rotation matrix.
vpRxyzVector & operator=(const vpRxyzVector &m)
Class that consider the case of the Euler angle using the x-y-z convention, where are respectively ...
Definition: vpRxyzVector.h:152
void buildFrom(const double phi, const double theta, const double psi)
Definition: vpRxyzVector.h:188
Class that consider the case of the parameterization for the rotation.