如何从中心点获得点的角度? [英] How to get angle of point from center point?

查看:58
本文介绍了如何从中心点获得点的角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有 2 个点 (x0,y0),它是圆的中心,另一个点 (x,y)(这是图像中圆边界上的红点).我怎样才能得到点的角度?

If I have 2 points (x0,y0) which is the center of the circle, and another point (x,y) (this is the red dot on the circle boundary in the image). How can I get the angle of the dot?

注意,它应该返回一个以度为单位的角度,从 [0,360).图像中的红点角度约为 70 度.

Note, it should return an angle in degrees, from [0,360). The red dot angle in the image is approximately 70 degrees.

我如何在 python 中做到这一点?

How can I do this in python?

谢谢

这似乎不起作用.

        (dx, dy) = (x0-x, y-y0)
        angle = atan(float(dy)/float(dx))
        if angle < 0:
            angle += 180

推荐答案

你们很亲近 :-)

改变这个:

 angle = atan(float(dy)/float(dx))

为此:

 angle = degrees(atan2(float(dy), float(dx)))

atan2() 函数介于 atan() 之间,因为它会考虑输入的符号并一直绕圆:

The atan2() function is between than atan() because it considers the signs to the inputs and goes all the way around the circle:

atan2(...)
    atan2(y, x)

    Return the arc tangent (measured in radians) of y/x.
    Unlike atan(y/x), the signs of both x and y are considered

degrees() 函数将弧度转换为度数:

The degrees() function converts from radians to degrees:

degrees(...)
    degrees(x)

    Convert angle x from radians to degrees.

此外,正如 Rich 和 Cody 指出的,您需要修正您的 dy 计算.

Also, as Rich and Cody pointed-out you need to fix your dy calculation.

这篇关于如何从中心点获得点的角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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