文章目录
笛卡尔坐标系atan2 函数的使用 atan2(delta_y , delta_x)atan 函数的使用 atan(delta_y / delta_x)atan 和 atan2 的异同取值范围
笛卡尔坐标系
对于平面坐标系,任一射线OP与x轴夹角θ的范围,可以取[0,2π)或者(-π,π],如无特殊说明, 我们统一使用后者。 将笛卡尔空间坐标系中的点 Pc = ( x , y , z ) 表示成球体坐标系中的形式 Ps = ( θ , ϕ , r )。 其中 根据球坐标的定义,要求θ∈[−π,π],ϕ∈[−π/2,π/2] ,r∈[0 , +∞)。 对于 θ,正切函数的周期是 π,因此反正切函数 arctan 一般也只取一个周期,其定义域是 R,值域是(−π/2 , π/2) 。为了解决这个问题,引入了 Arctan 函数,也就是 arctan2 函数。
![arctan2定义](https://img-blog.csdnimg.cn/img_convert/9827292abafa8dc50532b857c105df7d.png#pic_center)
atan2 函数的使用 atan2(delta_y , delta_x)
import math
a = math.atan2(400,-692.820)
# 2.6179936760992044
angle = a/math.pi*180
# 149.99998843242386
atan 函数的使用 atan(delta_y / delta_x)
import math
delta_y = 400
delta_x = -692.820
if delta_x == 0:
b = math.pi / 2.0
angle = b/math.pi*180
if delta_y == 0:
angle = 0.0
elif delta_y 0 and delta_x 0, a0)或 第四象限(b0)时,atan2(b,a) = atan(b/a) 点 (b,a) 落入第二象限 (b>0, a |