找到两点之间的角度,分别与水平轴成正比? [英] Find angle between two points, respective to horizontal axis?

查看:94
本文介绍了找到两点之间的角度,分别与水平轴成正比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个要点,一个总是在原点(0,0),另一个可以在世界其他任何地方.我想找到它们之间相对于水平轴的角度.

I have two points, one is always at the origin (0,0), and the other can be anywhere else in the world. I'd like to find the angle between them, respective to the horizontal axis.

     |     2
     |    /
     |   / 
     |  /  
     | /     
     |/ a  
  ---1-------------- (horizontal axis)
     |

  a = angle (~50 degrees, counter clockwise)

在上面,我将构造一个直角三角形,并使用sohcahtoa找出我想要的缺失角,但是当第二个点在不同象限中时,这种情况会有点难看:

In the above I would construct a right triangle and use sohcahtoa to figure out the missing angle I want, but it gets a bit ugly when the second point is in a different quadrant like in this case:

2    |
\    |
 \   |
  \  |
   \a|a   
    \|a
  ---1--------------
     |
     |

  a = angle (~135, counter clockwise)

根据第二点所处的象限,我最终遇到了许多不同的情况.我认为必须有一个更简单的通用解决方案.这有点像试图找到圆边上的点与其中心之间的角度,分别对应于原点的水平轴.

I just end up with a bunch of different cases depending on what quadrant the second point is in. I'm thinking there must be a much simpler, general solution. This is kind of like trying to find the angle between a point on the edge of a circle and its center, respective to the origin's horizontal axis.

执行此操作的好方法是什么?

What's a good way to do this?

推荐答案

大多数编程语言/API提供功能, atan2() ,它找到角度时将象限考虑在内.只需使用它即可.

Most programming languages/APIs provide a function, atan2(), which finds the angle and takes the quadrant into consideration. Just use that.

这篇关于找到两点之间的角度,分别与水平轴成正比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆