Python atan或atan2,我应该使用什么? [英] Python atan or atan2, what should I use?

查看:105
本文介绍了Python atan或atan2,我应该使用什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公式 f = arctan(ImZ/ReZ)

My formula f=arctan(ImZ/ReZ)

有两种选择:

选项1(阿旦):

ImZ=-4.593172163003
ImR=-4.297336384845

>>> z=y/x
>>> f1=math.atan(z)
>>> f1
0.8186613519278327

选项2(atan2)

>>> f=math.atan2(y,x)
>>> f
-2.3229313016619604

这两个结果为什么不同?

Why are these two results different?

推荐答案

Atan接受单个参数,Atan2接受两个参数.使用两个参数而不是一个参数的目的是收集有关输入符号的信息以便返回计算出的角度的适当象限,这对于单参数Atan来说是不可能的

Atan takes single argument and Atan2 takes two arguments.The purpose of using two arguments instead of one is to gather information on the signs of the inputs in order to return the appropriate quadrant of the computed angle, which is not possible for the single-argument Atan

Atan2的结果始终在-pi和pi之间.

Atan2 result is always between -pi and pi.

参考: https://en.wikipedia.org/wiki/Atan2

这篇关于Python atan或atan2,我应该使用什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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