Math.atan() 返回输入
我在 Math.atan 返回与输入相同的值时遇到问题。
public double inchToMOA( double in, double range){
double rangeIn = 36*range;
double atan = (in / rangeIn) * -1.0;
double deg = Math.atan(atan);
double moa = deg * 60;
return moa;
}
我将所有这些都放在一行中,但我将其分解为不同的变量,看看是否能找出它不起作用的原因。如果 in = -10 且 range = 300,则 atan 约为 -.00094。角度应约为 -.053 度,但 math.atan 返回 -.00094,与输入相同。
我的数字对于 math.atan 来说太小了吗?
I'm having a problem with Math.atan returning the same value as the input.
public double inchToMOA( double in, double range){
double rangeIn = 36*range;
double atan = (in / rangeIn) * -1.0;
double deg = Math.atan(atan);
double moa = deg * 60;
return moa;
}
I had this all in one line, but I broke it down into different variables to see if I could find out why it wasn't working. if in = -10 and range = 300, then atan is about -.00094. The angle should be about -.053 degrees, but math.atan is returning -.00094, the same as the input.
Is my number too small for math.atan?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
反正切在这里描述:
http://mathworld.wolfram.com/InverseTangent.html
我不知道不认为你的论点是这里的问题。
当然,您意识到计算机三角函数处理的是弧度而不是度数,对吧?
Inverse tangent is described here:
http://mathworld.wolfram.com/InverseTangent.html
I don't think your argument is the problem here.
You realize, of course, that computer trig functions deal in radians rather than degrees, right?
可能只是这样。如果您查看数学中正切函数的严格定义,您会发现对于较小的“x”值,
tan(x) = sin(x)/cos(x)
因此,您可以看到 lim x->0, tan(x) -> x 表示它的倒数,arctan,返回给定的值。至于 Math.atan 的数值准确性,我认为作者已经竭尽全力确保其数值准确性。
It might just be. If you look at the strict definition of the tangent function in mathematics what you see if that
tan(x) = sin(x)/cos(x)
for small values of "x"hence, you could see that
lim x->0, tan(x) -> x
meaning that it's inverse, arctan, returns the value it is given. As to the numerical accuracy of Math.atan I would think that the authors had gone to great lengths to ensure it's numerical accuracy.Math.atan
没有任何问题。对于接近零的输入,其值接近 1:1 线性,与原点相交。因此,越接近零,输入的变化就越小。There's nothing wrong with
Math.atan
. Its value is nearly 1:1 linear, intersecting the origin, for inputs close to zero. So the closer you are to zero the less change from the input there will be.