vba Tan() 返回错误值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7180478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tan() Returns Wrong Value
提问by Ron
I am trying to calculate angle between three points and I need to use the Tangent function tan()
. The weird thing is that VBA return wrong value.
我正在尝试计算三点之间的角度,我需要使用切线函数tan()
。奇怪的是 VBA 返回错误的值。
for example:
例如:
tan(209) = 0.554309051
棕褐色(209)= 0.554309051
but in VBA:
但在 VBA 中:
tan(209) = -.696695985548265
棕褐色(209)= -.696695985548265
My friend told me about something called "Normalize". but I didn't understand what he's talking about and how to do it. Why is this happening?
我的朋友告诉我一个叫做“标准化”的东西。但我不明白他在说什么以及如何去做。为什么会这样?
回答by Serith
回答by Jean-Fran?ois Corbett
In addition to confusing radians and degrees, I think you may be confusing tangentand arctangent.
除了混淆弧度和度数之外,我认为您可能会混淆tangent和arctangent。
In a comment, you say you call Tan
like this: Math.Tan((A(2) - B(2)) / (B(1) - A(1)))
. That is a very atypical way to be supplying an angle argument to a tangent! And in another comment, you imply that you expect this to give you an angle (EDIT: or "radians"). But tangent won't give you an angle or "radians"!
在评论,你说你叫Tan
这样的:Math.Tan((A(2) - B(2)) / (B(1) - A(1)))
。这是为切线提供角度参数的一种非常非典型的方式!在另一条评论中,您暗示您希望这会给您一个角度(编辑:或“弧度”)。但切线不会给你一个角度或“弧度”!
I can't believe nobody else is pointing this out. This physicist is outraged.
我不敢相信没有其他人指出这一点。这位物理学家被激怒了。
Based on this, I believe that what you really want is arctangent, i.e. Math.Atn((A(2) - B(2)) / (B(1) - A(1)))
. That will give you an angle (in radians) when supplied the length ratio of the opposite to adjacent sides.
基于此,我相信您真正想要的是反正切,即Math.Atn((A(2) - B(2)) / (B(1) - A(1)))
. 当提供对边与相邻边的长度比时,这将为您提供一个角度(以弧度为单位)。
Of course, the above is largely speculative, because I don't know what you really are trying to accomplish, but from what I can tease out of the bits of implicit information sprinkled across your question and comments, that is indeed what I would put my money on.
当然,以上内容在很大程度上是推测性的,因为我不知道您真正想要完成什么,但是从我可以从散布在您的问题和评论中的隐含信息中梳理出来的内容中,这确实是我要提出的我的钱。
回答by aevanko
(not addressing if using TAN is correct or not):
(如果使用 TAN 正确与否,则不寻址):
Perhaps your cell is formated in some special way and it's changing the value. In Excel 2007, both the worksheet funcion and VBA return -11.8641847236695for tan(209).That's different from what you have above.
也许您的单元格以某种特殊方式格式化并且它正在改变值。在 Excel 2007 中,工作表函数和 VBA都为tan(209)返回-11.8641847236695 。这和你上面说的不一样。
回答by Emilly Foster
It appears VB is like Excel where is assumes the input value for Tangent is in radians. If it is not in radians, you need to convert angles in degrees to radians.
看起来 VB 就像 Excel,其中假设 Tangent 的输入值以弧度为单位。如果不是弧度,则需要将角度以度为单位转换为弧度。
In Excel, you have to use the RADIANS() function to convert your data from angles to radians. Use the DEGREES() function to convert back.
在 Excel 中,您必须使用 RADIANS() 函数将数据从角度转换为弧度。使用 DEGREES() 函数转换回来。