Drawing membership function distribution in fuzzy mathematics under. NET Environment

Source: Internet
Author: User
Tags pow sin trim

In the. NET environment, the entire source code of the distribution map of the subordinate functions in fuzzy mathematics is drawn as follows:

Wherein: unit represents the graphic magnification, the larger the number of graphics magnification.

Interval represents the stepping scale, the smaller the value the more accurate (must be 0), but the slower the speed.

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; priv
ate 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.GROUPB Ox1.
Text = item1 + item2 + "graphics"; 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.Te
XT = "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.Te
XT = "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.TB
L.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.Te
XT = "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) ...
c 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 scale, the smaller the value the more accurate (must be size 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-(Floa
T) (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 <b; D + = interval) ... {x1 = o.x + d * unit; x2 = o.x + (d + interval) * unit; y1 = o.y-(float) (THIS.PICTUREBOX1.HEIGHT/4); y2 = o.y-(Floa
T) (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); 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-(unit*) (b-d-int
Erval)/(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-(unit*) (d-a-int
Erval)/(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-(flo
AT) (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); 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 * (System.Math.Pow (d1-d)/(d1-c), k));
y2 = o.y-(float) (unit * (System.Math.Pow (d1-d-Interval)/(d1-c), k));
P1 = new PointF (x1, y1);
P2 = new PointF (x2, y2);
E.graphics.drawline (Pens.blue, p1, p2); }} else if (type1 = 4) ...
{//set4 ();
PointF O1 = new PointF (THIS.PICTUREBOX1.WIDTH/2, THIS.PICTUREBOX1.HEIGHT/4);
E.graphics.drawstring ("1", Font, brush, O1); if (type2 = 3) ... {for (d = 0; d <= 2*a d = interval) ... 
{x1 = o.x + d * unit; x2 = o.x + (d + interval) * unit; y1 = o.y-(float) (System.Math.Exp ((d-a)/k) * (d-a)/k))
y2 = o.y-(float) (System.Math.Exp ((d-interval-a)/k) * ((d-interval-a)/k) (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 <= 2 * A; D + = interval) ... {x1 = o.x + d * unit; x2 = o.x + (d + interval) * unit; y1 = o.y-(float) (System.Math.Exp (-((d-a)/k) * ((d-a)/k)
) * unit);
y2 = o.y-(float) (System.Math.Exp ((d-interval-a)/k) * ((d-interval-a)/k) (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 <= 2 * A; D + = interval) ... {x1 = o.x + d * unit; x2 = o.x + (d + interval) * unit; y1 = o.y-(float) (System.Math.Exp (-((d-a)/k) * ((d-a)/k)
) * unit);
y2 = o.y-(float) (1-system.math.exp ((d-interval-a)/k) * ((d-interval-a)/k) (unit);
P1 = new PointF (x1, y1);
P2 = new PointF (x2, y2);
E.graphics.drawline (Pens.blue, p1, p2); }} else if (type1 = 5) ...
{//set5 ();
PointF O1 = new PointF (THIS.PICTUREBOX1.WIDTH/2, THIS.PICTUREBOX1.HEIGHT/4);
E.graphics.drawstring ("1", Font, brush, O1); if (type2 = 3) ... {for (d = 0; d <= 2 * A; D + = interval)
...  {x1 = o.x + d * unit; x2 = o.x + (d + interval) * unit; y1 = o.y-(float) ((1.0/(1+k*system.math.pow (d-a,l))) * unit); y2
= O.y-(float) ((1.0/(1 + k * System.Math.Pow (D-INTERVAL-A, L)) * 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 <= 2 * A; D + = interval) ... {x1 = o.x + d * unit; x2 = o.x + (d + interval) * unit; y1 = o.y-(float) ((1.0/(1 + k * System.Math.Pow (D-A, L)) *
unit);
y2 = o.y-(float) ((1.0/(1 + k * System.Math.Pow (D-INTERVAL-A, L)) * 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 <= 2 * A; D + = interval) ... {x1 = o.x + d * UNIT;
x2 = o.x + (d + interval) * UNIT;
Y1 = o.y-(float) ((1.0/(1 + k * System.Math.Pow (D-A, L)) * unit);
y2 = o.y-(float) ((1.0/(1 + k * System.Math.Pow (D-INTERVAL-A, L)) * unit);
P1 = new PointF (x1, y1);
P2 = new PointF (x2, y2);
E.graphics.drawline (Pens.blue, p1, p2); for (d = 2*a d <= 3*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 (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) * (Syst Em.
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 = n
EW 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 (); }
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.