AffineTransform 和翻转 y 轴

发布于 2024-10-08 14:40:15 字数 912 浏览 0 评论 0原文

当我尝试翻转我创建的坐标系的 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 不应该是一样的吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迟月 2024-10-15 14:40:15

您有一个拼写错误

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

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

You have a typo on

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

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

迷爱 2024-10-15 14:40:15

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文