在圆上找到点的角度 [英] Find angle of point on circle
问题描述
想象一下,我在屏幕上绘制了一个中心坐标为(cx,cy)的圆,并在该圆上选择了一个随机点(A).
Imagine I have drawn a circle with center coordinates (cx,cy) on the screen and a random point (A) is selected on the circle.
通过具有点A的坐标,我需要找到(a)的角度.
By having the the coordinates of point A, I need to find the angle of (a).
更新:
我尝试使用以下公式:
Math.toDegrees(Math.asin(((x - cx) / radius).toDouble()))
实际上与之相反(圆是通过向该圆角进给而创建的):
which is actually the reverse of (the circle is created by feeding angles to this one):
x = radius * Math.sin(Math.toRadians(angle.toDouble())) + cx
y = radius * Math.cos(Math.toRadians(angle.toDouble())) + cy
但是由于公式中不存在y坐标,因此答案可能是错误的.
But since the y coordinate is not present in the formula the answer could be wrong.
推荐答案
如果知道点A(x,y)的笛卡尔坐标,则可以通过将其转换为极坐标来找到角度theta,如下所示:
If you know the cartesian coordinates of the point A(x,y), then you can find the angle theta by converting it into polar coordinates as below:
double theta = Math.toDegrees(Math.atan2(y - cy, x - cx));
如果您的X轴为0度,则此公式有效,否则需要考虑偏移量.
This formula works if your X axis is in 0 degrees, otherwise you need to consider the offset.
这篇关于在圆上找到点的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!