예제 #1
0
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            points.Add(e.Location);
            Graphics g  = Graphics.FromImage(bmp);
            Brush    b1 = new SolidBrush(Color.Red);
            Brush    b2 = new SolidBrush(Color.Blue);

            Point clicked = new Point(e.X, e.Y);
            Point example = new Point();

            if (done)
            {
                //Evaluar punto de prueba una vez que el perceptron ya esta entrenado
                evaluarPunto(clicked);
                return;
            }
            if (e.Button == MouseButtons.Right)
            {
                g.FillEllipse(b1, e.X - 6, e.Y - 6, 10, 10);
                Y.Add(1);
            }
            else
            {
                g.FillEllipse(b2, e.X - 6, e.Y - 6, 10, 10);
                Y.Add(0);
            }

            //Instanciar el punto del plano con los valores dados
            PlanePoint planePoint = new PlanePoint(PointController.pixelsToPlane(clicked, bmp));

            pictureBox1.Image = bmp;
            pictureBox1.Refresh();
            planePoints.Add(planePoint);
        }
예제 #2
0
        private void dibujarLinea(double x1, double y1, double x2, double y2)
        {
            try
            {
                // Create pen.
                bmp2 = new Bitmap(bmp);
                Graphics g = Graphics.FromImage(bmp2);

                Point point1 = PointController.planeToPixels(x1, y1, bmp2);
                Point point2 = PointController.planeToPixels(x2, y2, bmp2);

                // Draw line to screen.
                if (bicolor == 0)
                {
                    g.DrawLine(blackPen, point1, point2); bicolor = 1;
                }
                else
                {
                    g.DrawLine(blackPen2, point1, point2); bicolor = 0;
                }

                pictureBox1.Image = bmp2;
                pictureBox1.Refresh();

                Thread.Sleep(200);
            }
            catch
            {
                if (x1 < 0)
                {
                    x1 = 0;
                }
                if (x2 < 0)
                {
                    x2 = 0;
                }
                if (y1 < 0)
                {
                    y1 = 0;
                }
                if (y2 < 0)
                {
                    y2 = 0;
                }
                dibujarLinea(x1, y1, x2, y2);
            }
        }
예제 #3
0
        private void evaluarPunto(Point p)
        {
            Graphics   g          = Graphics.FromImage(bmp);
            Brush      b1         = new SolidBrush(Color.Red);
            Brush      b2         = new SolidBrush(Color.Blue);
            double     calculo    = 0;
            PlanePoint planePoint = new PlanePoint(PointController.pixelsToPlane(p, bmp));

            calculo = (w[0] * -1 + w[1] * planePoint.X + w[2] * planePoint.Y);
            if (calculo > 0)
            {
                g.FillEllipse(b1, p.X - 6, p.Y - 6, 10, 10);
            }
            else
            {
                g.FillEllipse(b2, p.X - 6, p.Y - 6, 10, 10);
            }

            pictureBox1.Image = bmp;
            pictureBox1.Refresh();
        }