开发者

AffineTransform and flipping the y-axis

开发者 https://www.devze.com 2023-01-31 09:09 出处:网络
i ran into a strange problem when trying to flip the y-axis of a coordinate system that im creating: private AffineTransform getTransform() {

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 Transf开发者_开发问答orm 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?


You have a typo on

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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消