Rotation and scaling - how to make and get the right result?

I have a set of Java2D calls that draw vectors in a graphical context. I would like the image to be doubled in size and then rotated 90 degrees.

I am using the following code for this:

Graphics2D g2 = // ... get graphics 2d somehow ...
AffineTransform oldTransform = g2.getTransform();
AffineTransform newTransform = (AffineTransform)oldTransform.clone();
newTransform.concatenate(AffineTransform.getTranslateInstance(x1, x2));
newTransform.concatenate(AffineTransform.getScaleInstance((double)newW/(double)iconW, (double)newH/(double)iconH));
newTransform.concatenate(AffineTransform.getRotateInstance(Math.toRadians(rotationAngle), (double)iconW/2.0d, (double)iconH/2.0d));
// ... do my drawing ...

It rotates and scales, but the scale does not apply as we would like. It looks like it rotates before scaling, thereby making the image wider on the wrong axis.

Is there a better way to do this?

+3
source share
3 answers

, , . , , .

newTransform.concatenate(AffineTransform.getTranslateInstance(x1, x2));
newTransform.concatenate(AffineTransform.getRotateInstance(Math.toRadians(rotationAngle), (double)iconW/2.0d, (double)iconH/2.0d));
newTransform.concatenate(AffineTransform.getScaleInstance((double)newW/(double)iconW, (double)newH/(double)iconH));
+3

. , .

, , , .

+2

, , , .

+1

Source: https://habr.com/ru/post/1705354/


All Articles