Precedence in Eigen transformations and difference between pretranslate and translate

Multi tool use
Multi tool use


Precedence in Eigen transformations and difference between pretranslate and translate



I am a bit confused with the order used by Eigen when combining transformations.



What is the difference between translate() and pretranslate()?


translate()


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 )



?





The order in which C++ executes operands is sometimes arcane or not defined at all, but in this case it's left to right. The output of each function is the object on which the next function is being executed. Since the output of each function is a reference to *this, the object is modifying itself in a left to right chain.
– user4581301
9 hours ago


*this




2 Answers
2



pretranslate and translate differ in whether they apply the argument from the right or from the left


pretranslate


translate


A.pretranslate(B)



applies B on the from the left, returning B*A, while


B


B*A


A.translate(B)



applies it from the right, returning A*B.


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


A.translate(B)


translate


rotate


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.


pretranslate


translate



Kai already answered your question, but I'd like to strongly recommend avoiding those functions and write explicit code:


Vector3d t1, t2;
Matrix3d mat_rot;
Affine3d t_res = Translation3f(t2) * mat_rot * Translation3f(t1);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

XWzTa0MnI0h2p RqelVR jw4q OXXI3D DMSiu,E Fl3PMoizrLH Q30LyZ R4ifirU98jqfI
ctoBs2

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications