Ham*_*eni 2 java math android trigonometry
想象一下,我在屏幕上绘制了一个中心坐标为(cx,cy)的圆,并且在该圆上选择了一个随机点(A)。
通过获得点A的坐标,我需要找到(a)的角度。
更新:
我尝试使用以下公式:
Math.toDegrees(Math.asin(((x - cx) / radius).toDouble()))
Run Code Online (Sandbox Code Playgroud)
实际上是相反的(圆是通过向该圆角进给而创建的):
x = radius * Math.sin(Math.toRadians(angle.toDouble())) + cx
y = radius * Math.cos(Math.toRadians(angle.toDouble())) + cy
Run Code Online (Sandbox Code Playgroud)
但由于公式中不存在y坐标,因此答案可能是错误的。
如果知道点A(x,y)的笛卡尔坐标,则可以通过将其转换为极坐标来找到角度theta,如下所示:
double theta = Math.toDegrees(Math.atan2(y - cy, x - cx));
Run Code Online (Sandbox Code Playgroud)
如果您的X轴为0度,则此公式有效,否则需要考虑偏移量。
| 归档时间: |
|
| 查看次数: |
4085 次 |
| 最近记录: |