@@ -342,12 +342,10 @@ namespace dynamicgraph {
342
342
{
343
343
void operator ()( const MatrixHomogeneous& M,dg::Vector& res )
344
344
{
345
- MatrixRotation R; R = M.linear ();
346
- VectorUTheta r (R);
347
- dg::Vector t (3 ); t = M.translation ();
348
- res.resize (6 );
349
- for ( int i=0 ;i<3 ;++i ) res (i)=t (i);
350
- for ( int i=0 ;i<3 ;++i ) res (i+3 )=r.angle ()*r.axis ()(i);
345
+ res.resize (6 );
346
+ VectorUTheta r (M.linear ());
347
+ res.head <3 >() = M.translation ();
348
+ res.tail <3 >() = r.angle ()*r.axis ();
351
349
}
352
350
};
353
351
REGISTER_UNARY_OP ( HomogeneousMatrixToVector,MatrixHomoToPoseUTheta);
@@ -371,11 +369,12 @@ namespace dynamicgraph {
371
369
void operator ()( const dg::Vector& v,MatrixHomogeneous& res )
372
370
{
373
371
assert ( v.size ()>=6 );
374
- Eigen::Affine3d trans;
375
- trans = Eigen::Translation3d (v.head <3 >());
376
- dg::Vector ruth = v.tail <3 >();
377
- Eigen::Affine3d R (Eigen::AngleAxisd (ruth.norm (), ruth.normalized ()));
378
- res = R*trans;
372
+ res.translation () = v.head <3 >();
373
+ double theta = v.tail <3 >().norm ();
374
+ if (theta > 0 )
375
+ res.linear () = Eigen::AngleAxisd (theta, v.tail <3 >() / theta).matrix ();
376
+ else
377
+ res.linear ().setIdentity ();
379
378
}
380
379
};
381
380
REGISTER_UNARY_OP (PoseUThetaToMatrixHomo,PoseUThetaToMatrixHomo);
@@ -385,12 +384,10 @@ namespace dynamicgraph {
385
384
{
386
385
void operator ()( const MatrixHomogeneous& M,Vector& res )
387
386
{
388
- MatrixRotation R; R = M.linear ();
389
- VectorQuaternion r (R);
390
- dg::Vector t (3 ); t = M.translation ();
391
387
res.resize (7 );
392
- for ( int i=0 ;i<3 ;++i ) res (i)=t (i);
393
- for ( int i=0 ;i<4 ;++i ) res (i+3 )=r.coeffs ()(i);
388
+ res.head <3 >() = M.translation ();
389
+ Eigen::Map<VectorQuaternion> q (res.tail <4 >().data ());
390
+ q = M.linear ();
394
391
}
395
392
};
396
393
REGISTER_UNARY_OP (MatrixHomoToPoseQuaternion,MatrixHomoToPoseQuaternion);
0 commit comments