Tan() Returns Wrong Value

给你一囗甜甜゛ 提交于 2020-01-05 04:55:21

问题


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?


回答1:


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

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



回答2:


(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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/7180478/tan-returns-wrong-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!