AffineTransform和翻转y轴

4
我在创建一个坐标系并尝试翻转y轴时遇到了一个奇怪的问题:
   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 被设置为缩放和平移时,一切都很正常,除了我的 y 值被倒置了(最大值在坐标系底部,最小值在顶部)。我尝试通过反转 y 轴的比例因子来解决这个问题,但这并不起作用。

我需要让 Transform 旋转 PI 角度才能实现翻转的 y 轴吗?将 y 轴的比例因子乘以负 1 不应该是相同的效果吗?

2个回答

4

您在文本中打错了一个字。

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

(最后的Y应该是X。)也许就是这样。


1

通过 PI 旋转实际上根本不是正确的解决方案,因为它会翻转 X 轴和 Y 轴。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接