Tan() 返回错误值

发布于 2024-12-01 12:04:31 字数 276 浏览 0 评论 0原文

我正在尝试计算三点之间的角度,需要使用切线函数 tan()。奇怪的是VBA返回错误的值。

例如:

tan(209) = 0.554309051

但在 VBA 中:

tan(209) = -.696695985548265

我的朋友告诉我一个叫做“标准化”的东西。但我不明白他在说什么以及如何做。为什么会发生这种情况?

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.

for example:

tan(209) = 0.554309051

but in VBA:

tan(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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

娇俏 2024-12-08 12:04:31

根据 VBA 使用弧度。
将度数转换为弧度,( 度 * 2 * pi) / 360

tan((209 * 2 * 3.14)/360)

According to this VBA uses radians.
Convert degrees into radians , ( degrees * 2 * pi) / 360

tan((209 * 2 * 3.14)/360)
世界和平 2024-12-08 12:04:31

(不解决使用 TAN 是否正确的问题):

也许您的单元格以某种特殊方式格式化,并且它正在更改值。
在 Excel 2007 中,工作表函数和 VBA 都为 tan(209) 返回 -11.8641847236695 这与上面的不同。

(not addressing if using TAN is correct or not):

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.8641847236695 for tan(209). That's different from what you have above.

野生奥特曼 2024-12-08 12:04:31

除了混淆弧度和度数之外,我认为您可能还会混淆 正切 和 < a href="http://en.wikipedia.org/wiki/Arctangent" rel="nofollow">反正切。

在评论中,您说您像这样调用 TanMath.Tan((A(2) - B(2)) / (B(1) - A(1)))。这是向切线提供角度参数的一种非常非典型的方式!在另一条评论中,您暗示您希望这给您一个角度(编辑:或“弧度”)。但切线不会给你一个角度或“弧度”!

我不敢相信没有其他人指出这一点。这位物理学家很愤怒。

基于此,我相信你真正想要的是反正切,即Math.Atn((A(2) - B(2)) / (B(1) - A(1 )))。当提供相对边与相邻边的长度比时,这将为您提供一个角度(以弧度为单位)。

当然,以上内容在很大程度上是推测性的,因为我不知道您真正想要完成什么,但从我可以从您的问题和评论中散布的隐含信息中梳理出的内容来看,这确实是我想要的我的钱。

In addition to confusing radians and degrees, I think you may be confusing tangent and 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"!

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.

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.

梦幻的心爱 2024-12-08 12:04:31

VB 看起来就像 Excel,其中假设切线的输入值以弧度为单位。如果不是弧度,则需要将角度单位转换为弧度。

在 Excel 中,您必须使用 RADIANS() 函数将数据从角度转换为弧度。使用 DEGREES() 函数转换回来。

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.

In Excel, you have to use the RADIANS() function to convert your data from angles to radians. Use the DEGREES() function to convert back.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文