我有一组AffineTranform实例。根据具体情况,我需要连接其中的任何一个 - 这里的条件并不重要。这样做时,我发现连接的顺序似乎很重要。看一下这个例子,我有:
在示例中,我创建了以下组合: 1.一个x刻度x平移 2.两个x translatex量表
遵循Java文档,连接时矩阵应该相乘,但查看示例代码的输出会显示不同的结果。
Java版:Java 6 SE Update 30
示例:
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)); //is false
System.out.println("");
AffineTransform two = new AffineTransform();
System.out.println("two: " + two);
two.concatenate(translate);
System.out.println("two + translate: " + two);
two.concatenate(scale);
System.out.println("two + translate + scale: " + two);
System.out.println("Is two equal to original: " + original.equals(two)); //is true
System.out.println("");
}
}
输出:
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
Java是否存在问题或我的代码中是否有错误?
谢谢你的提示。