Affine matrix from rotation and translation
Posted: 2010-10-09T18:32:54-07:00
Hi,
I am using Magick++ library version 6.6.3 on Windows7. The Magick++ tutorial contains the following lines:
A very hilarious example is the DrawableRotation and DrawableTranslation objects that require 'angle/2' (instead of 'angle') and 'displacement/2' (instead of 'displacement') as arguments. If this could be regarded as some hacker joke made by one of the library implementers, more serious problems seem to exist: for example, the above two coordinate system transformations don't work together at all (they give nonsensical effects when drawing objects on a canvas).
According to this, there are two bugs:
1. Combining DrawableRotation and DrawableTranslation gives incorrect results.
2. The arguments specified to these objects need to be angle/2 (instead of angle) and displacement/2 (instead of displacement).
Although the document refers to library version 6.2.5.4, both these bugs still exist on version 6.6.3. I have discovered the cause of both these bugs as described below:
1. Combining multiple affine transforms is achieved by multiplying the affine matrices for each transform. The order of transformations is important since matrix multiplication is not commutative. For example, if first transform is a rotation R, and second is translation T, then the combined transform should be T*R. However, the code is doing R*T. Look at magick\draw.c, function DrawImage. The matrix multiplication is doing current * affine, where current is the existing affine matrix, and affine is the new matrix. The correct multiplication should be affine * current. Same situation exists also in wand\draw-wand.c, function AdjustAffine.
2. The above affine transformations are being applied twice - first time by calling AdjustAffine each time a drawable transformation is found in the drawing list, and second time in DrawImage mentioned above. That's why the arguments given to the drawable objects have to be half of their correct value.
I hope these bugs will get fixed in the next version of the library.
Regards,
Swami
I am using Magick++ library version 6.6.3 on Windows7. The Magick++ tutorial contains the following lines:
A very hilarious example is the DrawableRotation and DrawableTranslation objects that require 'angle/2' (instead of 'angle') and 'displacement/2' (instead of 'displacement') as arguments. If this could be regarded as some hacker joke made by one of the library implementers, more serious problems seem to exist: for example, the above two coordinate system transformations don't work together at all (they give nonsensical effects when drawing objects on a canvas).
According to this, there are two bugs:
1. Combining DrawableRotation and DrawableTranslation gives incorrect results.
2. The arguments specified to these objects need to be angle/2 (instead of angle) and displacement/2 (instead of displacement).
Although the document refers to library version 6.2.5.4, both these bugs still exist on version 6.6.3. I have discovered the cause of both these bugs as described below:
1. Combining multiple affine transforms is achieved by multiplying the affine matrices for each transform. The order of transformations is important since matrix multiplication is not commutative. For example, if first transform is a rotation R, and second is translation T, then the combined transform should be T*R. However, the code is doing R*T. Look at magick\draw.c, function DrawImage. The matrix multiplication is doing current * affine, where current is the existing affine matrix, and affine is the new matrix. The correct multiplication should be affine * current. Same situation exists also in wand\draw-wand.c, function AdjustAffine.
2. The above affine transformations are being applied twice - first time by calling AdjustAffine each time a drawable transformation is found in the drawing list, and second time in DrawImage mentioned above. That's why the arguments given to the drawable objects have to be half of their correct value.
I hope these bugs will get fixed in the next version of the library.
Regards,
Swami