c#画正弦波

/// <summary>
/// 画正弦曲线
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
  Bitmap bitmap = new Bitmap(pictureBoxFrequencyDomain.Width, pictureBoxFrequencyDomain.Height,          PixelFormat.Format32bppArgb);

  Graphics g = Graphics.FromImage(bitmap);
  Pen pen = new Pen(Color.Red, 1);
  double x1 = 10;
  double y1 = 0;
  for (double x = 1; x < pictureBoxFrequencyDomain.Width; x++)
  {
    //SIN最大值为1,而我图上用了100像素,所以有
    //100/1=100 故而y要乘100;
    // x/180*Math.PI 这个表达式把角度换成弧度值
    double y = Math.Sin(x / 180 * Math.PI)*60;

    //SIN值一个循环为360度,而我图上用了200像素表示,所以有:
    //360/200=1.8 故而x值要除1.8
    g.DrawLine(pen, (float)x1, (float)y1 + 60, (float)(x / 1.8) + 10, (float)y + 60);
    x1 = x / 1.8 + 10;
    y1 = y;
  }

  pictureBoxFrequencyDomain.Image = bitmap;
}

posted @ 2014-04-20 15:36  sidely  阅读(4276)  评论(0编辑  收藏  举报