我在创建一个坐标系并尝试翻转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 不应该是相同的效果吗?