AffineTransform and y-axis flipping

I ran into some strange problem while trying to flip the y axis of the coordinate system that im creates:

private AffineTransform getTransform() { if (transform == null) { transform = new AffineTransform(); double scaleX = (double) this.getWidth() / (coordinateSystem.getMaxX() - coordinateSystem.getMinY()); double scaleY = (double) this.getHeight() / (coordinateSystem.getMaxY() - coordinateSystem.getMinY()); transform.setToScale(scaleX, scaleY); double deltaX = (coordinateSystem.getMaxX() - coordinateSystem.getMinX()) / 2; double deltaY = (coordinateSystem.getMaxY() - coordinateSystem.getMinY()) / 2; transform.translate(deltaX, deltaY); } return transform; } 

AffineTransform is configured to scale and translate. and everything works fine, except that my y values ​​are inverted (the maximum value is the bottom of the coordinate system, the minimum value is at the top). I tried to switch this by inverting the scale factor for the y axis. but it didn’t work.

Should I let Transform rotate with PI to achieve the inverted y axis? Shouldn't the scaling factor for the y axis be multiplied by minus 1?

+4
source share
2 answers

You have a typo on

 double scaleX = (double) this.getWidth() / (coordinateSystem.getMaxX() - coordinateSystem.getMinY()); 

(The last Y should be X ) Perhaps this.

+4
source

Rotating with PI is NOT really the right solution, as it will flip the X axis as well as the Y axis.

+1
source

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


All Articles