Math.sin - 冲出想法
我正在尝试使用 math.sin 和 math.cos 在我的程序中做一条移动边缘线。我得到了所有的数学结果,并且似乎正确地相加(我使用来自单击的鼠标位置和移动鼠标变量来确定绘制区域。然后我使用宽度值来给它边缘偏移。
我使用 math.cos 来找出 X 和 Y 位置中的点偏移多远。 cos(Angle) 的值似乎绝对疯狂,从 +1 到 -1
Angle = 29.153788462442
Cos 。根据窗口计算器 = 0.8733152733324487151754721490934
Cos 根据 Math.Cos(Angle) = -0.637571130025255
我尝试将角度转换为浮点数和整数,以防小数位导致问题,但无济于事
。提出这些答案
lblInOpts.Text = Math.Cos(Angle).ToString() + " " + Angle.ToString();
。弧度和使用方式与 MSDN 似乎建议的方式相同。
I'm trying math.sin and math.cos to do a moving edge line in my program. I get all the math and it seems to add up properly (I use mouse location from a click and a moving mouse variable to determine the draw areas. I then use a width value to give it the edge offset.
I use math.cos to find how far in to offset the points in the X and Y locations. While doing this, the value of cos(Angle) seems to go absolutely crazy, from +1 to -1. Here's an example.
Angle = 29.153788462442
Cos as per window calculator = 0.8733152733324487151754721490934
Cos as per Math.Cos(Angle) = -0.637571130025255
I tried converting Angle to a float and an int in case the decimal place was causing it an issue, no avail.
This is the code I am using to bring up those answers.
lblInOpts.Text = Math.Cos(Angle).ToString() + " " + Angle.ToString();
The document is in degrees, switched over from radians and being use the same way MSDN seems to suggest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要从度数转换为弧度:
You need to convert from degrees to radians:
您正在传递以度为单位的角度,
Math.Cos
需要以弧度为单位的角度You are passing the angle in degrees,
Math.Cos
expects an angle in radiansWindows 计算器的结果是解释为度数的角度的余弦值。
C# 代码的结果是解释为弧度的角度的余弦,相当于
1670.389...
度。要将代码中的度数转换为弧度,请使用
The result from the Windows Calculator is the cosine of the angle interpreted as degrees.
The result from your C# code is the cosine of the angle interpreted as radians, which is the equivalent of
1670.389...
degrees.To convert degrees to radians in your code, use
-0.637571130025255 是 29.153788462442 弧度(1670.38903571 度)的余弦。检查 Math.Cos() 的文档 - 它是否采用弧度或度数作为参数?
-0.637571130025255 is the cosine of 29.153788462442 radians (1670.38903571 degrees). Check the documentation of Math.Cos() - does it take an argument in radians or degrees?