讲解.NET环境下绘制模糊数学中隶属函数分布图第1/5页
程序员文章站
2023-11-14 15:15:40
绘制模糊数学中隶属函数分布图 using system; using system.collections.generic...
绘制模糊数学中隶属函数分布图
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.collections;
using system.windows.forms;
using system.drawing.imaging;
using system.drawing.drawing2d;
namespace imagefuzzy
...{
public partial class form1 : form
...{
private int type1;
private int type2;
private string item1;
private string item2;
private float a;
private float b;
private float c;
private float d1;
private float k;
private float l;
private float tempx;
private float tempy;
public void initarray()
...{
type1 = 0;
type2 = 0;
k = 2;
item1 = this.combobox1.text.tostring();
item2 = this.combobox2.text.tostring();
this.groupbox1.text = item1 + item2 + "图形";
a = float.parse(this.tba.text.trim().tostring());
b = float.parse(this.tbb.text.trim().tostring());
c = float.parse(this.tbc.text.trim().tostring());
d1 = float.parse(this.tbd.text.trim().tostring());
k = float.parse(this.tbk.text.trim().tostring());
l = float.parse(this.tbl.text.trim().tostring());
type1 = this.combobox1.selectedindex+1;
type2 = this.combobox2.selectedindex+1;
}
private void delete()
...{
a = 0;
b = 0;
c = 0;
d1 = 0;
k = 0;
l = 0;
}
private void set1()
...{
this.tba.text = "1";
this.tbb.text = "2";
this.tbc.text = "3";
this.tbd.text = "4";
this.tbk.text = "1";
this.tbl.text = "2";
}
private void set2()
...{
this.tba.text = "1";
this.tbb.text = "1.5";
this.tbc.text = "2";
this.tbd.text = "2.5";
this.tbk.text = "1";
this.tbl.text = "2";
}
private void set3()
...{
this.tba.text = "0.5";
this.tbb.text = "1.5";
this.tbc.text = "2";
this.tbd.text = "3";
this.tbk.text = "3";
this.tbl.text = "2";
}
private void set4()
...{
this.tba.text = "1.5";
this.tbb.text = "1.5";
this.tbc.text = "2";
this.tbd.text = "2.5";
this.tbk.text = "0.5";
this.tbl.text = "2";
}
private void set5()
...{
this.tba.text = "2";
this.tbb.text = "2.5";
this.tbc.text = "3";
this.tbd.text = "3.5";
this.tbk.text = "4";
this.tbl.text = "6";
}
private void set6()
...{
this.tba.text = "0.5";
this.tbb.text = "1.5";
this.tbc.text = "2";
this.tbd.text = "2.5";
this.tbk.text = "2";
this.tbl.text = "4";
}
public form1()
...{
initializecomponent();
}
private void form1_load(object sender, eventargs e)
...{
//set1();
}
private void form1_paint(object sender, painteventargs e)
...{
}
private void picturebox1_paint(object sender, painteventargs e)
...{
float d;
float x1;
float x2;
float y1;
float y2;
pointf p1;
pointf p2;
int unit = 40;//放大倍数
font font = new font("ms ui gothic", 12);
solidbrush brush = new solidbrush(color.black);
float interval = 0.001f; //步进刻度,值越小越精确(必须大小0),但速度也越慢
pointf o = new pointf(this.picturebox1.width / 2, this.picturebox1.height / 2);
e.graphics.drawline(pens.red, 0, this.picturebox1.height / 2, this.picturebox1.width, this.picturebox1.height / 2);
e.graphics.drawline(pens.red, this.picturebox1.width / 2, 0, this.picturebox1.width / 2, this.picturebox1.height);
e.graphics.drawstring("o", font, brush, o);
if (type1 == 0)
...{
for (d = -6.28f; d < 6.28f; d += interval)
...{
x1 = o.x + d * unit;
x2 = o.x + (d + interval) * unit;
y1 = o.y - (float)(unit * system.math.sin(d));
y2 = o.y - (float)(unit * system.math.sin(d + interval));
p1 = new pointf(x1, y1);
p2 = new pointf(x2, y2);
e.graphics.drawline(pens.black, p1, p2);
}
}
else if (type1 == 1)
...{
//set1();
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)(this.picturebox1.height / 4);
y2 = o.y - (float)(this.picturebox1.height / 4);
p1 = new pointf(x1, y1);
p2 = new pointf(x2, y2);
e.graphics.drawline(pens.black, p1, p2);
tempx = x2;
tempy = this.picturebox1.height/2;
}
pointf o2 = new pointf(tempx, tempy);
e.graphics.drawstring(a.tostring(), font, brush, o2);
}
else if (type2 == 2)
...{
for (d = a; d < 2*a; d += interval)
...{
x1 = o.x + d * unit;
x2 = o.x + (d + interval) * unit;
y1 = o.y - (float)(this.picturebox1.height / 4);
y2 = o.y - (float)(this.picturebox1.height / 4);
p1 = new pointf(x1, y1);
p2 = new pointf(x2, y2);
e.graphics.drawline(pens.blue, p1, p2);
}
pointf o2 = new pointf(tempx, tempy);
e.graphics.drawstring(a.tostring(), font, brush, o2);
}
else if (type2 == 3)
...{
for (d = a; d
...{
x1 = o.x + d * unit;
x2 = o.x + (d + interval) * unit;
y1 = o.y - (float)(this.picturebox1.height / 4);
y2 = o.y - (float)(this.picturebox1.height / 4);
p1 = new pointf(x1, y1);
p2 = new pointf(x2, y2);
e.graphics.drawline(pens.blue, p1, p2);
}
pointf o2 = new pointf(tempx, tempy);
e.graphics.drawstring(a.tostring(), font, brush, o2);
}
}
else if (type1 == 2)
...{
//set2();
pointf o1 = new pointf(this.picturebox1.width/2, this.picturebox1.height / 4);
e.graphics.drawstring("1", font, brush, o1);
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.collections;
using system.windows.forms;
using system.drawing.imaging;
using system.drawing.drawing2d;
namespace imagefuzzy
...{
public partial class form1 : form
...{
private int type1;
private int type2;
private string item1;
private string item2;
private float a;
private float b;
private float c;
private float d1;
private float k;
private float l;
private float tempx;
private float tempy;
public void initarray()
...{
type1 = 0;
type2 = 0;
k = 2;
item1 = this.combobox1.text.tostring();
item2 = this.combobox2.text.tostring();
this.groupbox1.text = item1 + item2 + "图形";
a = float.parse(this.tba.text.trim().tostring());
b = float.parse(this.tbb.text.trim().tostring());
c = float.parse(this.tbc.text.trim().tostring());
d1 = float.parse(this.tbd.text.trim().tostring());
k = float.parse(this.tbk.text.trim().tostring());
l = float.parse(this.tbl.text.trim().tostring());
type1 = this.combobox1.selectedindex+1;
type2 = this.combobox2.selectedindex+1;
}
private void delete()
...{
a = 0;
b = 0;
c = 0;
d1 = 0;
k = 0;
l = 0;
}
private void set1()
...{
this.tba.text = "1";
this.tbb.text = "2";
this.tbc.text = "3";
this.tbd.text = "4";
this.tbk.text = "1";
this.tbl.text = "2";
}
private void set2()
...{
this.tba.text = "1";
this.tbb.text = "1.5";
this.tbc.text = "2";
this.tbd.text = "2.5";
this.tbk.text = "1";
this.tbl.text = "2";
}
private void set3()
...{
this.tba.text = "0.5";
this.tbb.text = "1.5";
this.tbc.text = "2";
this.tbd.text = "3";
this.tbk.text = "3";
this.tbl.text = "2";
}
private void set4()
...{
this.tba.text = "1.5";
this.tbb.text = "1.5";
this.tbc.text = "2";
this.tbd.text = "2.5";
this.tbk.text = "0.5";
this.tbl.text = "2";
}
private void set5()
...{
this.tba.text = "2";
this.tbb.text = "2.5";
this.tbc.text = "3";
this.tbd.text = "3.5";
this.tbk.text = "4";
this.tbl.text = "6";
}
private void set6()
...{
this.tba.text = "0.5";
this.tbb.text = "1.5";
this.tbc.text = "2";
this.tbd.text = "2.5";
this.tbk.text = "2";
this.tbl.text = "4";
}
public form1()
...{
initializecomponent();
}
private void form1_load(object sender, eventargs e)
...{
//set1();
}
private void form1_paint(object sender, painteventargs e)
...{
}
private void picturebox1_paint(object sender, painteventargs e)
...{
float d;
float x1;
float x2;
float y1;
float y2;
pointf p1;
pointf p2;
int unit = 40;//放大倍数
font font = new font("ms ui gothic", 12);
solidbrush brush = new solidbrush(color.black);
float interval = 0.001f; //步进刻度,值越小越精确(必须大小0),但速度也越慢
pointf o = new pointf(this.picturebox1.width / 2, this.picturebox1.height / 2);
e.graphics.drawline(pens.red, 0, this.picturebox1.height / 2, this.picturebox1.width, this.picturebox1.height / 2);
e.graphics.drawline(pens.red, this.picturebox1.width / 2, 0, this.picturebox1.width / 2, this.picturebox1.height);
e.graphics.drawstring("o", font, brush, o);
if (type1 == 0)
...{
for (d = -6.28f; d < 6.28f; d += interval)
...{
x1 = o.x + d * unit;
x2 = o.x + (d + interval) * unit;
y1 = o.y - (float)(unit * system.math.sin(d));
y2 = o.y - (float)(unit * system.math.sin(d + interval));
p1 = new pointf(x1, y1);
p2 = new pointf(x2, y2);
e.graphics.drawline(pens.black, p1, p2);
}
}
else if (type1 == 1)
...{
//set1();
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)(this.picturebox1.height / 4);
y2 = o.y - (float)(this.picturebox1.height / 4);
p1 = new pointf(x1, y1);
p2 = new pointf(x2, y2);
e.graphics.drawline(pens.black, p1, p2);
tempx = x2;
tempy = this.picturebox1.height/2;
}
pointf o2 = new pointf(tempx, tempy);
e.graphics.drawstring(a.tostring(), font, brush, o2);
}
else if (type2 == 2)
...{
for (d = a; d < 2*a; d += interval)
...{
x1 = o.x + d * unit;
x2 = o.x + (d + interval) * unit;
y1 = o.y - (float)(this.picturebox1.height / 4);
y2 = o.y - (float)(this.picturebox1.height / 4);
p1 = new pointf(x1, y1);
p2 = new pointf(x2, y2);
e.graphics.drawline(pens.blue, p1, p2);
}
pointf o2 = new pointf(tempx, tempy);
e.graphics.drawstring(a.tostring(), font, brush, o2);
}
else if (type2 == 3)
...{
for (d = a; d
...{
x1 = o.x + d * unit;
x2 = o.x + (d + interval) * unit;
y1 = o.y - (float)(this.picturebox1.height / 4);
y2 = o.y - (float)(this.picturebox1.height / 4);
p1 = new pointf(x1, y1);
p2 = new pointf(x2, y2);
e.graphics.drawline(pens.blue, p1, p2);
}
pointf o2 = new pointf(tempx, tempy);
e.graphics.drawstring(a.tostring(), font, brush, o2);
}
}
else if (type1 == 2)
...{
//set2();
pointf o1 = new pointf(this.picturebox1.width/2, this.picturebox1.height / 4);
e.graphics.drawstring("1", font, brush, o1);
1