【发布时间】:2014-05-29 00:49:05
【问题描述】:
我已经知道如何根据角度在圆的圆周上找到一个点。我用来执行此操作的代码如下。
x = Math.sin(Math.toRadians(angle)) * radius;
y = Math.cos(Math.toRadians(angle)) * radius;
我正在尝试撤消这个过程。
到目前为止,我有这段代码,它只适用于小于或等于 90 度的角度。
DecimalFormat df = new DecimalFormat("###.####");
angleFromX = normalize(
Double.parseDouble(
df.format(
Math.toDegrees(
Math.asin(
(x / radius)
)
)
)
)
);
angleFromY = normalize(
Double.parseDouble(
df.format(
Math.toDegrees(
Math.acos(
(y / radius)
)
)
)
)
);
这是上面使用的normalize 方法。
public static double normalize(double angle) {
angle %= 360;
if (angle < 0) {
angle = angle + 360;
}
return angle;
}
【问题讨论】:
标签: java geometry trigonometry cartesian-coordinates