【问题标题】:How can I find the angle between two points of a circle?如何找到圆的两点之间的角度?
【发布时间】:2017-08-11 10:25:49
【问题描述】:

我有圆和半径的 centerX 和 centerY 值。现在我有 (x1, y1) 点位于圆上。我想知道该点的圆角。

我尝试了以下公式来获得 (x1, y1) 的角度。但它没有给出通用的解决方案。

radian = Math.Atan2(y1 - Cy, x1 - Cx);
angle = radian * (180 / Math.PI);

请参考我的要求截图。

请让我提出我做错了什么。?

【问题讨论】:

标签: c# math geometry trigonometry


【解决方案1】:

MSDN documentation page for Atan2,它返回一个介于 -180 和 180 度之间的结果(-pi 到 pi 弧度)。另一方面,您需要 0 到 360。为此,只需将 360 添加到最终答案中(如果它是否定的)。

radian = Math.Atan2(y1 - Cy, x1 - Cx);
angle = radian * (180 / Math.PI);
if (angle < 0.0) 
   angle += 360.0;

【讨论】:

  • 既然span已经在[-180, 180]之间,如果答案是否定的,用户不应该在最终答案上加180吗?
  • @Sometowngeek No. 例如当 atan2 给出 -90(正上方中心)时,OP 所需的相应结果将是 270 度。添加 180 会得到 90,这是不正确的。
  • 有什么直接的解决方案可以覆盖360度..?
  • 我删除了我的第二条评论,因为我刚刚意识到在我做任何事情之前我需要早上喝咖啡。 (我现在脑子很慢)
  • 我试图将它与How to get angle of point from center point? 进行比较——这使用python
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
相关资源
最近更新 更多