AffineTransform 和翻转 y 轴
当我尝试翻转我创建的坐标系的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有一个拼写错误
(最后一个
Y
应该是X
。)也许就是这样。You have a typo on
(Last
Y
should be anX
.) Perhaps that's it.按 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.