问题描述
我正在使用UIAcceleration
进行旋转.我有相反的一面,相邻的一面,但我想计算出tan-1(y/x)反正切.
I am using UIAcceleration
for rotation. I have opposite side, adjacent side, but I want to calculate tan-1(y/x) inverse tan.
推荐答案
始终使用atan2(y,x)代替atan(y/x),有两个原因. David Maymudes提到了一个(x = 0的问题).另一个是atan2()处理-π的全部范围.到+&pi ;,而atan()仅为您提供-&pi/2和+π/2之间的输出,而不能区分(x,y)=(2,2)和(x,y)=( -2,-2),因为在进行除法运算时会丢失符号信息,并且仅将商y/x传递给atan().
Always use atan2(y,x) instead of atan(y/x), for two reasons. One is mentioned by David Maymudes (problems with x=0). The other is that atan2() deals with the full range from -π to +π, whereas atan() only gives you an output between -π/2 and +π/2, and cannot distinguish between (x,y)=(2,2) and (x,y)=(-2,-2) since you lose the sign information when you do the division and pass only the quotient y/x into atan().
这篇关于如何计算反正切?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!