本文给出了有个在.NET环境下绘制模糊数学中隶属函数分布图的实例代码,并对其作了简单讲解,大家可以学习一下。
作者:常青藤 来源:CSDN 2007年11月26日
关键字:
以下是引用片段:
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)(unit*((b-d)/(b-a)));
y2=o.Y-(float)(unit*((b-d-interval)/(b-a)));
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)(unit*((d-a)/(b-a)));
y2=o.Y-(float)(unit*((d-a-interval)/(b-a)));
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
for (d = b; d <= (b+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);
}
}
else if (type2 == 3)
...{
for (d = a; d < b; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)(unit * ((d - a) / (b - a)));
y2 = o.Y - (float)(unit * ((d - a - interval) / (b - a)));
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);
}
for (d = c; d < d1; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)(unit * ((d1 - d) / (d1 - c)));
y2 = o.Y - (float)(unit * ((d1 - d - interval) / (d1 - c)));
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
}
}
else if (type1 == 3)
...{
//set3();
PointF o1 = new PointF(this.pictureBox1.Width / 2, this.pictureBox1.Height / 4);
e.Graphics.DrawString("1", font, brush, o1);
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)(unit * (System.Math.Pow((b-d)/(b-a),k)));
y2 = o.Y - (float)(unit * (System.Math.Pow((b - d - interval) / (b - a),k)));
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)(unit * (System.Math.Pow((d - a) / (b - a), k)));
y2 = o.Y - (float)(unit * (System.Math.Pow((d - a - interval) / (b - a), k)));
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}
for (d = b; d <= (a+b); 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);
}
}
else if (type2 == 3)
...{
for (d = a; d < b; d += interval)
...{
x1 = o.X + d * unit;
x2 = o.X + (d + interval) * unit;
y1 = o.Y - (float)(unit * (System.Math.Pow((d - a) / (b - a), k)));
y2 = o.Y - (float)(unit * (System.Math.Pow((d - a - interval) / (b - a), k)));
p1 = new PointF(x1, y1);
p2 = new PointF(x2, y2);
e.Graphics.DrawLine(Pens.Blue, p1, p2);
}