二维图形的问题:等效的 AffineTransform 代码?

Problems with 2D Graphics: equivalent AffineTransform codes?

我正在学习 Java。我已经完成了它,但我对 2D 图形有很大的问题。在讲座中,关于AffineTransform,我们了解到这些代码:

 1. translate(double x, doubley),
 2. scale(double x, double y),
 3. rotate(double theta),
 4. shear(double x, double y),
 5. transform(AffineTransform at) and
 6. setTransform(AffineTransform).

我现在最大的问题是我们的教授说有了这些代码,关于转换的一切都是可行的。这就是他向我们展示的全部内容。

AffineTransform at = AffineTransform.getTranslateInstance(this.pos.getX(), this.pos.getY());
at.concatenate(AffineTransform.getScaleInstance(this.scaleX, this.scaleY));

Shape shape = at.createTransformedShape(this.form);
Point2D center = getCenter(shape);

at = AffineTransform.getRotateInstance(this.winkel, center.getX(), center.getY());
return at.createTransformedShape(shape);

例如,我现在的问题是这样的。为什么我们不使用例如 at.rotate 而我们使用 at = AffineTransform.getRotateInstance?

为什么我们使用 at=AffineTransform.getTranslateInstance 而不是 at.translate

我不明白。我们的教授说这些命令已经足够了,现在又添加了新的命令?我可以制作这段代码中的内容吗?等同于我列出的代码?

因为我们的教授说我可以用我列出的代码做任何事情,但是导师从来没有用过它们!他使用了这些我没有得到的代码,我一直在练习和训练这些列出的代码,现在我很惊讶。

我的主要问题是:我能否以某种方式使用列出的代码获得与此粘贴代码相同的结果?有什么办法可以代替这个吗?

请注意 AffineTransform method concatenate() uses matrix multiplication, which is not commutative. The advantage of concatenating transformations is that multiplication may be performed once and the result reused repeatedly. Focusing on the concrete example cited here,给定一个名为 at:

的身份转换
AffineTransform at = new AffineTransform();

下面三个公式是等价的:

at.translate(SIZE/2, SIZE/2);
at.scale(60, 60);
at.rotate(Math.PI/4);

at.concatenate(AffineTransform.getTranslateInstance(SIZE / 2, SIZE / 2));
at.concatenate(AffineTransform.getScaleInstance(60, 60));
at.concatenate(AffineTransform.getRotateInstance(Math.PI / 4));

at.preConcatenate(AffineTransform.getRotateInstance(Math.PI / 4));
at.preConcatenate(AffineTransform.getScaleInstance(60, 60));
at.preConcatenate(AffineTransform.getTranslateInstance(SIZE / 2, SIZE / 2));