예제 #1
0
 private void bresenham(double dx, double dy, int x1, int y1, int x2, int y2, Bitmap b)
 {
     if (dx != 0 && dy != 0)
     {
         if (Math.Abs(dy) > Math.Abs(dx))
         {
             if (x1 < x2)
             {
                 if (y1 < y2)
                 {
                     FiltroV.BresenhamHigh(x1, y1, b, dx, dy, 1, 1);
                 }
                 else
                 {
                     dy *= -1;
                     FiltroV.BresenhamHigh(x1, y1, b, dx, dy, 1, -1);
                 }
             }
             else
             {
                 dx *= -1;
                 if (y1 < y2)
                 {
                     FiltroV.BresenhamHigh(x1, y1, b, dx, dy, -1, 1);
                 }
                 else
                 {
                     dy *= -1;
                     FiltroV.BresenhamHigh(x1, y1, b, dx, dy, -1, -1);
                 }
             }
         }
         else
         {
             if (x1 < x2)
             {
                 if (y1 < y2)
                 {
                     FiltroV.BresenhamLow(x1, y1, b, dx, dy, 1, 1);
                 }
                 else
                 {
                     dy *= -1;
                     FiltroV.BresenhamLow(x1, y1, b, dx, dy, 1, -1);
                 }
             }
             else
             {
                 dx *= -1;
                 if (y1 < y2)
                 {
                     FiltroV.BresenhamLow(x1, y1, b, dx, dy, -1, 1);
                 }
                 else
                 {
                     dy *= -1;
                     FiltroV.BresenhamLow(x1, y1, b, dx, dy, -1, -1);
                 }
             }
         }
         pbviewport.Image = b;
     }
 }
예제 #2
0
        private void pbsegmentos_MouseMove(object sender, MouseEventArgs e)
        {
            x2 = e.X;
            y2 = e.Y;
            b  = (Bitmap)aux.Clone();

            double dx = x2 - x1;
            double dy = y2 - y1;

            if (x1 != 0 && y1 != 0 && modoseg.Equals("po"))
            {
                bresenham(dx, dy, b);
            }
            else if (mstatus)
            {
                switch (modoseg)
                {
                case "er":
                    if (dx != 0)
                    {
                        double m = dy / dx;

                        if (x1 < x2)
                        {
                            FiltroV.EqGeralRetaQ1(m, x1, y1, dx, b, 1);
                        }
                        else
                        {
                            dx *= -1;
                            FiltroV.EqGeralRetaQ1(m, x1, y1, dx, b, -1);
                        }
                        if (y1 < y2)
                        {
                            FiltroV.EqGeralRetaQ2(m, x1, y1, dy, b, 1);
                        }
                        else
                        {
                            dy *= -1;
                            FiltroV.EqGeralRetaQ2(m, x1, y1, dy, b, -1);
                        }
                        pbsegmentos.Image = b;
                    }
                    break;

                case "dr":
                    if (dx != 0)
                    {
                        if (x1 > x2)
                        {
                            FiltroM.retaDda(b, x2, x1, y2, y1, Color.Black);
                        }
                        else
                        {
                            FiltroM.retaDda(b, x1, x2, y1, y2, Color.Black);
                        }
                        pbsegmentos.Image = b;
                    }
                    break;

                case "br":
                    bresenham(dx, dy, b);
                    break;

                case "ec":
                    FiltroC.EqGeralCircunferencia(x1, y1, x2, y2, b);
                    pbsegmentos.Image = b;
                    break;

                case "tr":
                    FiltroM.circTrigonometria(x1, y1, x2, y2, b);
                    pbsegmentos.Image = b;
                    break;

                case "pm":
                    FiltroM.circPontomedio(x1, y1, x2, y2, b);
                    pbsegmentos.Image = b;
                    break;

                case "el":
                    FiltroM.elipse(Math.Abs(x2 - x1), Math.Abs(y2 - y1), x1, y1, b);
                    pbsegmentos.Image = b;
                    break;
                }
            }
        }