I am a bit confused with the order used by Eigen when combining transformations.
What is the difference between translate()
and pretranslate()
?
Because in practice I get different results when I do this:
Eigen::Affine3d t_res = Eigen::Affine3d::Identity();
t_res.pretranslate(t1)
.translate(t2)
.rotate(t3);
...and this:
Eigen::Affine3d t_res = Eigen::Affine3d::Identity();
t_res.translate(t1)
.translate(t2)
.rotate(t3);
Also, for the last code snippet, does Eigen do this
t_res = (t1 * ( t2 * t3 ))
or this
t_res = ((t1 * t2) * t3 )
?
pretranslate
and translate
differ in whether they apply the argument from the right or from the left
A.pretranslate(B)
applies B
on the from the left, returning B*A
, while
A.translate(B)
applies it from the right, returning A*B
.
Regarding the order, A.translate(B)
returns a reference to the resulting matrix, so it will iteratively call translate
/rotate
on the results of the previous operation, doing
t_res = (((t_res* t1) * t2) * t3 )
But as matrix multiplication is associative, the order of the operations only matters when it comes to numerical errors due to the floating point representation.
The order of the matrices however does affect the result (as the multiplication is not commutative), which is why pretranslate
and translate
give different results.
Edit: As ggael pointed out, for t_res
being the identity, both versions should give the same result