C# Winform 画Sin函数方法

 

void DrawSinLine(Graphics gph,Pen p)
        {
            //1. 中心原点 260 150   以120像素高 为单位1  以120像素宽为pi
            double d = -6.2;
            while (d <= 6.283)
            {
                double dbl = Math.Sin(d);

                //Console.WriteLine("sin:{0}",dbl);

                //计算坐标 120 为pi 

                double px, py;
                if (d < 0)
                {
                    px = 250 - Math.Abs(d) * 120 / Math.PI;  // x
                }
                else
                {
                    px = d * 120 / Math.PI + 250;
                }

                //----------------计算y的坐标
                if (dbl < 0)
                {
                    py = Math.Abs(dbl) * 120 + 140;            //y
                }
                else
                {
                    py = 140 - (dbl * 120);
                }

                int x = (int)px + 10;
                int y = (int)py + 10;
                //Console.WriteLine("sin:x=>{0},y=>{1}", x, y);
                p.Color = Color.Black;
                gph.DrawLine(p, x, y, x, y);
                d += 0.02;
            }
            p.Dispose();   //释放资源
            gph.Dispose();
           
        }

posted @ 2012-02-22 17:57  至道中和  阅读(1245)  评论(0编辑  收藏  举报