Chaining transformations using Matrix class gives wrong results
mat_tx = Matrix().translate(-5,-5,0) # translate by -5,-5
mat_rot = Matrix().rotate(3.14159/4, 0,0,1) # Rotate by pi/4 around z
mat_tf = mat_rot.multiply(mat_tm)
The above gives correct transformation matrix for translating and rotating an object.
I was expecting this to work but it gives strange result
mat_tf = Matrix().translate(-5,-5,0).rotate(3.14159/4,0,0,1)
Both mat_tfs are different but trying to translate (7,7) with first gives correct point (0,2.82) but gives some weird result for second mat_tf.
Can the Matrix class be used like this? If not, there needs to be a mention in the docs.
I wonder if it's not a confusion about the effect of x.multiply(y) (instead of y.multiply(x))
>>> from kivy.graphics.transformation import Matrix
>>> mat_tf = Matrix().translate(-5,-5,0).rotate(3.14159/4,0,0,1)
>>>
>>> mat_tx = Matrix().translate(-5,-5,0) # translate by -5,-5
>>> mat_rot = Matrix().rotate(3.14159/4, 0,0,1) # Rotate by pi/4 around z
>>> mat_rot.multiply(mat_tx).tolist() == mat_tf.tolist()
False
>>> mat_tx.multiply(mat_rot).tolist() == mat_tf.tolist()
True
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.
If you're having trouble installing Kivy, make sure to check out the installation docs for Windows, Linux and macOS.
Let us know if this comment was made in error, and we'll be happy to reopen the issue.
It's true - the transformations can't be chained, what Kivy usually does when using those matrices is that it applies individual transforms to the identity matrix and then multiplies the resulting matrices with one another. The way scale and translate are implemented in particular will only work on the identity matrix.
This is probably something we'd want to fix (instead of merely documenting it) - being correct will still work on the identity matrix (as it does currently) but will also allow chaining transformations.