如何在绘制正弦函数时提高精度。 [英] How Do I Increase Precision When Drawing Sine Functions.

查看:156
本文介绍了如何在绘制正弦函数时提高精度。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我需要制作一个根据输入绘制模拟调制功能的应用程序。我试过在Java和C#中都这样做,我遇到了同样的问题。在c#中,我一直在使用我在这些论坛上找到的ZedGraph,这就是问题所在。当我将'x'的值增加0.1时,我得到了一个结果,但它是高度分散的,现在我想通过降低增量以获得更多点来提高质量。当我将它降低到0.1以下时,它会变得非常疯狂。我甚至试过用一个简单的公式来绘制Cos:



Hello

I need to make an application that draws analog modulation function depending on the inputs. I have tried doing it both in Java and C# and I run into the same problem. In c# I've been using ZedGraph that I found on these forums and here's the problem. When I increase the value of 'x' by 0.1 I get a result, but it's highly fragmented, now I wanted to improve on the quality by lowering the increment to get more points. When I lower it below 0.1 like to 0.01 it goes completely crazy. I've even tried with a simple formula to draw Cos:

for ( double x = 0; x < 2;)
            {
                double y = Math.Cos(180.0 * x);



                list.Add( x, y );
                x += 0.01;
            }





再次适用于x比例为0.1然后如果我降低则会发疯。



这是我得到的0.1: https:// imagizer .imageshack.us / v2 / 443x301q90 / 836 / kbiv.jpg [ ^ ]



这是我得到的0.01:https://imagizer.imageshack.us/v2/443x301q90/836/2g44.jpg [ ^ ]



任何帮助都会很高赞。



and again it works for x scale to 0.1 then it goes crazy if I go lower.

Here's what i get for 0.1: https://imagizer.imageshack.us/v2/443x301q90/836/kbiv.jpg[^]

And here's what I get for 0.01: https://imagizer.imageshack.us/v2/443x301q90/836/2g44.jpg[^]

Any help would be highly appreciated.

推荐答案

你假设 Math.Cos 方法的参数是虽然它必须在弧度Math.Cos方法 [ ^ ]。尝试

You are assuming that Math.Cos method's argument is in degrees while it must be in radians ("Math.Cos Method" at MSDN[^]. Try
double delta = Mat.PI/180/100; // 1/100 of a degree
for ( double x = 0; x < 2 * Math.PI; x += delta)
{
    double y = Math.Cos(x);
    list.Add( x, y );
}


这与准确性无关。准确性很好。你只是在绘制的一组线上没有足够的点。增加点的密度。不要太害怕放太多 - 现在,图形比你想象的要快得多。 :-)



-SA
This is not about accuracy. The accuracy is just fine. You just put not enough points on the plotted set of lines. Increase the density of points. Don't be afraid to much to put too many of them — these days, graphics is much faster than you may think. :-)

—SA


这篇关于如何在绘制正弦函数时提高精度。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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