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 轴的比例因子来切换它。但这不起作用。

我是否必须让变换按 PI 旋转,以实现翻转的 y 轴?将 y 轴的比例因子乘以负 1 不应该相同吗?

4

2 回答 2

4

你有一个错字

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

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

于 2010-12-21T11:42:38.470 回答
1

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

于 2010-12-21T18:41:39.840 回答