本文给出了有个在.NET环境下绘制模糊数学中隶属函数分布图的实例代码,并对其作了简单讲解,大家可以学习一下。
作者:常青藤 来源:CSDN 2007年11月26日
关键字:
以下是引用片段:
else if (type1 == 6)
...{
//set6();
PointF o1 = new PointF(this.pictureBox1.Width / 2, this.pictureBox1.Height / 4);
e.Graphics.DrawString("1", font, brush, o1);
if (type2 == 3)
...{
for (d =-b; d < -a; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)((0.5 + 0.5 * System.Math.Sin((d-(a+b)/2)*(System.Math.PI/(b-a)))) * unit);
y2 = o.Y - (float)((0.5 + 0.5 * System.Math.Sin((d-interval - (a + b) / 2) * (System.Math.PI / (b - a)))) * unit);
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
for (d = -a; d < a; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)(1* unit);
y2 = o.Y - (float)(1 * unit);
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
for (d = a; d < b; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)((0.5 - 0.5 * System.Math.Sin((d - (a + b) / 2) * (System.Math.PI / (b - a)))) * unit);
y2 = o.Y - (float)((0.5 - 0.5 * System.Math.Sin((d - interval - (a + b) / 2) * (System.Math.PI / (b - a)))) * unit);
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
}
else if (type2 == 1)
...{
for (d = 0; d < a; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)(1 * unit);
y2 = o.Y - (float)(1 * unit);
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
for (d = a; d < b; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)((0.5 - 0.5 * System.Math.Sin((d - (a + b) / 2) * (System.Math.PI / (b - a)))) * unit);
y2 = o.Y - (float)((0.5 - 0.5 * System.Math.Sin((d - interval - (a + b) / 2) * (System.Math.PI / (b - a)))) * unit);
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
}
else if (type2 == 2)
...{
for (d = a; d < b; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)((0.5 + 0.5 * System.Math.Sin((d - (a + b) / 2) * (System.Math.PI / (b - a)))) * unit);
y2 = o.Y - (float)((0.5 + 0.5 * System.Math.Sin((d - interval - (a + b) / 2) * (System.Math.PI / (b - a)))) * unit);
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
for (d = b; d < c; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)(1 * unit);
y2 = o.Y - (float)(1 * unit);
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
}
}
}
private void button1_Click(object sender, EventArgs e)
...{
InitArray();
Graphics g = Graphics.FromHwnd(this.pictureBox1.Handle);
PaintEventArgs e1 = new PaintEventArgs(g, this.pictureBox1.ClientRectangle);
this.pictureBox1_Paint(this.pictureBox1, e1);
g.Dispose();
}
}
}