Math.Cos&安培; Math.Sin在C# [英] Math.Cos & Math.Sin in C#

查看:210
本文介绍了Math.Cos&安培; Math.Sin在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想的东西,我认为应该是相当简单的。我有一个角度,位置和距离,我想找到X,从这些信息中Y坐标。

I'm trying something that I thought should be reasonably simple. I have an angle, a position and a distance and I want to find the X,Y co-ordinates from this information.

随着90度的例子输入I转换值以弧度用下面的代码:

With an example input of 90 degrees I convert the value to radians with the following code:

public double DegreeToRadian(float angle)
{
  return Math.PI * angle / 180.0;
}

这给了我1.5707963267949弧度
后来,当我使用

This gives me 1.5707963267949 radians Then when I use

Math.Cos(radians)

我最终的一个答案是:6.12303176911189E-17

I end up with an an answer of: 6.12303176911189E-17

到底是什么回事? 90度的余弦值应为0,所以为什么我收到这样的越轨行为......更重要的是我怎么能阻止它?

What the heck is going on? The cosine of 90 degrees should be 0, so why am I getting such a deviance... and more importantly how can I stop it?

推荐答案

让我来回答与另外一个你的问题:有多远,你认为6.12303176911189E-17为0?你叫什么的偏差的居然是由于浮点数在内部存储的方式。我建议你​​阅读下面的文章。在.NET中,他们使用的是 IEEE 754标准储存。

Let me answer your question with another one: How far do you think 6.12303176911189E-17 is from 0? What you call deviance is actually due to the way floating point numbers are internally stored. I would recommend you reading the following article. In .NET they are stored using the IEEE 754 standard.

这篇关于Math.Cos&安培; Math.Sin在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆