C#画正余弦函数图像的简单例子

 float pi = 3.1415f;
            Graphics g = e.Graphics;
            g.PageUnit = GraphicsUnit.Inch;
            Pen mypen = new Pen(Color.Black, 2 / g.DpiX);
            float x = 0, y = 0;
            Pen pen = new Pen(Color.Red,2/g.DpiX);
            g.DrawLine(pen, new Point(0, 1), new Point(6, 1));// 画X轴
            g.DrawLine(pen, new Point(1,0), new Point(1, 2));//画Y轴
            for (x = 0f; x < 8 * pi; x = x + 0.005f)
            {
            y=(float)Math.Sin((double)x);

            g.DrawEllipse(mypen, 8 * x / g.DpiX+0.5f, 8 * y / g.DpiY+1, 0.005f, 0.005f);

你可能感兴趣的:(c#.net)