4

i ran into a strange problem when trying to flip the y-axis of a coordinate system that im creating:

   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;
    }

The AffineTransform is set to scaling and translation. and everything works fine except that my y-values are inverted (max value is a the bottom of the coordinate system, min value is at the top). I tried switching this by inverting the scale factor for the y axis. but this was not working.

Do i have to let the Transform rotate by PI, to achieve the flipped y axis? Shouldn't multiplying the scale factor for the y axis by minus 1 be the same?

fasseg
  • 17,504
  • 8
  • 62
  • 73

2 Answers2

4

You have a typo on

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

(Last Y should be an X.) Perhaps that's it.

aioobe
  • 413,195
  • 112
  • 811
  • 826
1

Rotating by PI is actually NOT a right solution at all, since it will flip the X axis as well as the Y.

ysap
  • 7,723
  • 7
  • 59
  • 122