public FormFuzzy()
 {
     InitializeComponent();
     comboBoxDelay.SelectedIndex = 0;
     mySwitch += MotionDown;
     mySwitch += MotionUp;
     gr = new Randare(pictureBox1.Width, pictureBox1.Height, 0, 100, 1, 25);
     pos1 = pictureBox1.Location;
     pos2 = pictureBox2.Location;
     size1 = pictureBox1.Size;
     size2 = pictureBox1.Size;
     try
     {
         A = new NumarFuzzy(Convert.ToInt32(textBoxCentruA.Text), Convert.ToInt32(textBoxAlfaA.Text), Convert.ToInt32(textBoxBetaA.Text), gr.Max);
         B = new NumarFuzzy(Convert.ToInt32(textBoxCentruB.Text), Convert.ToInt32(textBoxAlfaB.Text), Convert.ToInt32(textBoxBetaB.Text), gr.Max);
         alfa = Convert.ToDouble(textBoxAlfa.Text);
         if (alfa < 0 || alfa > 1)
             throw new Exception();
         pictureBox1.Refresh();
         pictureBox2.Refresh();
         ValidareButoane(true);
     }
     catch
     {
         MessageBox.Show("Date gresite !");
         A = null;
         B = null;
     }
 }
Beispiel #2
0
        public static void Calc(ref NumarFuzzy N)
        {
            float x1 = N.C - N.A, x2 = N.C, x3 = N.C + N.B, y1 = 0, y2 = 1, y3 = 0;
            float a1 = 1 / (x2 - x1) * (y2 - y1);
            float b1 = y2 - x2 * a1;
            float a2 = 1 / (x3 - x2) * (y3 - y2);
            float b2 = y3 - x3 * a2;

            for (int i = 0; i < N.vect.Length; ++i)
            {
                if (i >= N.C - N.A && i < N.C + N.B)
                    if (i < N.C)
                    {
                        // x1 = c - a; x2 = c; y1 = pb.Height - offset; y2 = offset;
                        N.vect[i] = a1 * i + b1;
                    }
                    else
                    {
                        // x1 = c; x2 = c + b; y1 = offset; y2 = pb.Height - offset;
                        N.vect[i] = a2 * i + b2;
                    }
                else
                    N.vect[i] = 0;
            }
        }
Beispiel #3
0
 public static void Grafic(Graphics g, Randare gr, NumarFuzzy N, Pen p)
 {
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     for (int i = 1; i < N.vect.Length; ++i)
     {
         g.DrawLine(p, gr.RandeazaW(i - 1), gr.RandeazaH(N.vect[i - 1]), gr.RandeazaW(i), gr.RandeazaH(N.vect[i]));
     }
     g.DrawString((N.C - N.A).ToString(), new Font("Tahoma", 10), Brushes.Black, gr.RandeazaW(N.C - N.A) - 10, gr.RandeazaH(0));
     g.DrawString((N.C + N.B).ToString(), new Font("Tahoma", 10), Brushes.Black, gr.RandeazaW(N.C + N.B) - 10, gr.RandeazaH(0));
 }
 public static void Concentrare(NumarFuzzy A, Graphics g, Randare gr)
 {
     Grafics.Sistem(g, gr);
     float[] vect = new float[gr.Max];
     vect[0] = A.vect[0] * A.vect[0];
     for (int i = 1; i < 100; ++i)
     {
         vect[i] = A.vect[i] * A.vect[i];
         g.DrawLine(Pens.Aqua, gr.RandeazaW(i - 1), gr.RandeazaH(vect[i - 1]), gr.RandeazaW(i), gr.RandeazaH(vect[i]));
     }
 }
 public static void Dilatare(NumarFuzzy A, Graphics g, Randare gr)
 {
     Grafics.Sistem(g, gr);
     float[] vect = new float[gr.Max];
     vect[0] = (float)Math.Round(Math.Sqrt(A.vect[0]));
     for (int i = 1; i < 100; ++i)
     {
         vect[i] = (float)Math.Sqrt(Math.Abs(A.vect[i]));
         g.DrawLine(Pens.Aqua, gr.RandeazaW(i - 1), gr.RandeazaH(vect[i - 1]), gr.RandeazaW(i), gr.RandeazaH(vect[i]));
     }
 }
 public static void Int(NumarFuzzy A, NumarFuzzy B, Graphics g, Randare gr)
 {
     Grafics.Sistem(g, gr);
     float[] vect = new float[gr.Max];
     vect[0] = Math.Max(A.vect[0], B.vect[0]);
     for (int i = 1; i < 100; ++i)
     {
         if (A.vect[i] < B.vect[i])
         {
             vect[i] = A.vect[i];
         }
         else
         {
             vect[i] = B.vect[i];
         }
         g.DrawLine(Pens.Aqua, gr.RandeazaW(i - 1), gr.RandeazaH(vect[i - 1]), gr.RandeazaW(i), gr.RandeazaH(vect[i]));
     }
 }
        public static NumarFuzzy Div(NumarFuzzy A, NumarFuzzy B, Graphics g, Randare gr, double alfa)
        {
            float ml, mr, nl, nr, ql, qr;
            bool draw = false, este = false;
            int i = 0;
            Randare temp = null;
            NumarFuzzy C = null;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            while (i <= 50)
            {
                MN(out ml, out mr, out nl, out nr, A, B, i * 0.02f);

                ql = Math.Min(Math.Min(ml / nl, ml / nr), Math.Min(mr / nl, mr / nr));
                qr = Math.Max(Math.Max(ml / nl, ml / nr), Math.Max(mr / nl, mr / nr));

                if (!draw)
                {
                    temp = new Randare(gr.WindowW, gr.WindowH, ql, qr, 1, gr.Offset);
                    C = new NumarFuzzy(A.C + B.C, ql, qr, gr.Max);
                    C.vect[i] = ql;
                    C.vect[99 - i] = qr;
                    Grafics.Sistem(g, temp);
                    draw = !draw;
                }
                else
                {
                    C.vect[i] = ql;
                    C.vect[99 - i] = qr;
                    g.DrawLine(Pens.Aqua, temp.RandeazaW(C.vect[i - 1]), temp.RandeazaH((i - 1) * 0.02f), temp.RandeazaW(ql), temp.RandeazaH(i * 0.02f));
                    g.DrawLine(Pens.Aqua, temp.RandeazaW(C.vect[100 - i]), temp.RandeazaH((i - 1) * 0.02f), temp.RandeazaW(qr), temp.RandeazaH(i * 0.02f));
                    if (alfa < i * 0.02 && !este)
                    {
                        g.DrawLine(Pens.YellowGreen, temp.RandeazaW(C.vect[i - 1]), temp.RandeazaH((i - 1) * 0.02f), temp.RandeazaW(C.vect[100 - i]), temp.RandeazaH((i - 1) * 0.02f));
                        g.DrawString(Math.Round(C.vect[i - 1], 1).ToString(), new Font("Tahoma", 10), Brushes.Black, temp.RandeazaW(C.vect[i - 1]) - 25, temp.RandeazaH((i - 1) * 0.02f));
                        g.DrawLine(Pens.YellowGreen, temp.RandeazaW(C.vect[i - 1]), temp.RandeazaH(0), temp.RandeazaW(C.vect[i - 1]), temp.RandeazaH((i - 1) * 0.02f));
                        g.DrawString(Math.Round(C.vect[100 - i], 1).ToString(), new Font("Tahoma", 10), Brushes.Black, temp.RandeazaW(C.vect[100 - i]) + 5, temp.RandeazaH((i - 1) * 0.02f));
                        g.DrawLine(Pens.YellowGreen, temp.RandeazaW(C.vect[100 - i]), temp.RandeazaH(0), temp.RandeazaW(C.vect[100 - i]), temp.RandeazaH((i - 1) * 0.02f));
                        este = !este;
                    }
                }
                ++i;
            }
            return C;
        }
Beispiel #8
0
 public static void AlfaCut(Graphics g, Randare gr, NumarFuzzy N, double alfa)
 {
     float x1 = 0, y1 = -1, x2 = 0, y2 = -1;
     for (int i = 0; i < N.vect.Length; ++i)
     {
         if (alfa < N.vect[i] && -1 == y1)
         {
             x1 = i - 1;
             y1 = N.vect[i - 1];
         }
         if (alfa > N.vect[i] && -1 != y1 && -1 == y2)
         {
             x2 = i;
             y2 = N.vect[i];
         }
     }
     LinieOrizontala(gr, g, x1, x2, y1, Pens.Coral);
     g.DrawString(Math.Round(x1, 0).ToString(), new Font("Tahoma", 10), Brushes.Black, gr.RandeazaW(x1) - 25, gr.RandeazaH(y1));
     LinieVerticala(gr, g, x1, y1, Pens.Coral);
     g.DrawString(Math.Round(x2, 0).ToString(), new Font("Tahoma", 10), Brushes.Black, gr.RandeazaW(x2) + 5, gr.RandeazaH(y2));
     LinieVerticala(gr, g, x2, y1, Pens.Coral);
 }
 public static void Intensificare(NumarFuzzy A, Graphics g, Randare gr)
 {
     Grafics.Sistem(g, gr);
     float[] vect = new float[gr.Max];
     if (A.vect[0] < 0.5)
         vect[0] = 2 * A.vect[0] * A.vect[0];
     else
         vect[0] = 1 - 2 * (1 - A.vect[0]) * ( 1 -  A.vect[0]);
     vect[0] = (float)Math.Round(Math.Sqrt(A.vect[0]));
     for (int i = 1; i < 100; ++i)
     {
         if (A.vect[i] < 0.5)
             vect[i] = 2 * A.vect[i] * A.vect[i];
         else
             vect[i] = 1 - 2 * (1 - A.vect[i]) * (1 - A.vect[i]);
         g.DrawLine(Pens.Aqua, gr.RandeazaW(i - 1), gr.RandeazaH(vect[i - 1]), gr.RandeazaW(i), gr.RandeazaH(vect[i]));
     }
 }
Beispiel #10
0
 private static void MN(out float ml,out float mr,out float nl,out float nr, NumarFuzzy A, NumarFuzzy B, float a)
 {
     ml = (A.C - A.A) + A.A * a;
     mr = (A.C + A.B) - A.B * a;
     nl = (B.C - B.A) + B.A * a;
     nr = (B.C + B.B) - B.B * a;
 }
Beispiel #11
0
 public static void Putere(NumarFuzzy A, double n, Graphics g, Randare gr)
 {
     Grafics.Sistem(g, gr);
     float[] vect = new float[gr.Max];
     vect[0] = (float)Math.Pow(A.vect[0],n);
     for (int i = 1; i < 100; ++i)
     {
         vect[i] = (float)Math.Pow(A.vect[i], n);
         g.DrawLine(Pens.Aqua, gr.RandeazaW(i - 1), gr.RandeazaH(vect[i - 1]), gr.RandeazaW(i), gr.RandeazaH(vect[i]));
     }
 }
 private void buttonCalc_Click(object sender, EventArgs e)
 {
     try
     {
         A = new NumarFuzzy(Convert.ToInt32(textBoxCentruA.Text), Convert.ToInt32(textBoxAlfaA.Text), Convert.ToInt32(textBoxBetaA.Text), gr.Max);
         B = new NumarFuzzy(Convert.ToInt32(textBoxCentruB.Text), Convert.ToInt32(textBoxAlfaB.Text), Convert.ToInt32(textBoxBetaB.Text), gr.Max);
         alfa = Convert.ToDouble(textBoxAlfa.Text);
         if (alfa < 0 || alfa > 1)
             throw new Exception();
         pictureBox1.Refresh();
         pictureBox2.Refresh();
         button3.Enabled = true;
         button4.Enabled = true;
         button5.Enabled = true;
         button6.Enabled = true;
         button7.Enabled = true;
     }
     catch
     {
         MessageBox.Show("Date gresite !");
         A = null;
         B = null;
     }
 }