I have a collection of AffineTranform instances. Depending on the specific conditions, I need to concatenate any of them - the conditions are not important here. In doing so, I found that the concatenation order seems to have some significance. Looking at an example, I:
- one original tranformation 'original' that scales and translates2. one unit matrix 'one'
- one identical matrix 'two'
- one transformation scale that scales
- one tranformation 'translate' that translates
In this example, I create the following combinations: 1. one x scale x translation 2. two scales x translatex
Following the Java documentation, matrices should be multiplied when concatenated, but looking at the result of the sample code shows different results.
Java Version: Java 6 SE Update 30
Example:
package affinetransformationtest; import java.awt.geom.AffineTransform; public class AffineTransformationTest { public static void main(String[] args) { AffineTransform original = new AffineTransform(10, 0.0, 0.0, 100, 2, 3); System.out.println("original: " + original); System.out.println(""); AffineTransform scale = AffineTransform.getScaleInstance(10, 100); AffineTransform translate= AffineTransform.getTranslateInstance(2, 3); AffineTransform one = new AffineTransform(); System.out.println("one: " + one); one.concatenate(scale); System.out.println("one + scale: " + one); one.concatenate(translate); System.out.println("one + scale + translate: " + one); System.out.println("Is one equal to original: " + original.equals(one));
Output:
original: AffineTransform[[10.0, 0.0, 2.0], [0.0, 100.0, 3.0]] one: AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]] one + scale: AffineTransform[[10.0, 0.0, 0.0], [0.0, 100.0, 0.0]] one + scale + translate: AffineTransform[[10.0, 0.0, 20.0], [0.0, 100.0, 300.0]] Is one equal to original: false two: AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]] two + translate: AffineTransform[[1.0, 0.0, 2.0], [0.0, 1.0, 3.0]] two + translate + scale: AffineTransform[[10.0, 0.0, 2.0], [0.0, 100.0, 3.0]] Is two equal to original: true
Is there a problem with Java or am I having an error in my code?
Thanks for any hint.