Draw a map of membership functions in Fuzzy Mathematics
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;
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 + "Graph ";
A = float. Parse (this. Serves. 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. b7-. 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. b7-. 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. b7-. 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. b7-. 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. b7-. 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. b7-. 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 picturebox#paint (object sender, PaintEventArgs e)
...{
Float d;
Float x1;
Float x2;
Float y1;
Float y2;
PointF p1;
PointF p2;
Int unit = 40; // magnification
Font font = new Font ("ms ui Gothic", 12 );
SolidBrush brush = new SolidBrush (Color. Black );
Float interval = 0.001F; // step-by-step scale. The smaller the value, the more precise the value (the size must be 0), but the slower the speed.
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 );