Ejemplo n.º 1
0
        // Нарисовать эллипс
        public static void DrawEllipse(Bitmap b, Point center, int radiusX, int radiusY, Color color)
        {
            // x^2/a^2+y^2/b^2=1

            int rx2 = radiusX * radiusX; // a^2
            int ry2 = radiusY * radiusY; // b^2

            // Производная при y`=-1 , является границей для оптимального рисования
            // y`=-b/a*x/sqrt(a^2-x^2)
            int rdel2 = (int)Math.Round(rx2 / Math.Sqrt(rx2 + ry2));

            int    x = 0, y = 0;
            double m = (double)radiusY / radiusX; // b/a

            for (x = 0; x <= rdel2; x++)
            {
                y = (int)Math.Round(Math.Sqrt(rx2 - x * x) * m);  //y=b/a*sqrt(a^2-x^2)
                DrawHack.DrawSymmetric(b, center, x, y, color);
            }

            // Производная , является границей для оптимального рисования
            rdel2 = (int)Math.Round(ry2 / Math.Sqrt(rx2 + ry2));
            m     = 1 / m; //переворачиваем m

            for (y = 0; y <= rdel2; y++)
            {
                x = (int)Math.Round(Math.Sqrt(ry2 - y * y) * m); //аналогично выше
                DrawHack.DrawSymmetric(b, center, x, y, color);
            }
        }
Ejemplo n.º 2
0
        public static void DrawCircle(Bitmap bitmap, Point center, int RX, Color color)
        {
            int x = 0;
            int y = RX;
            int p = 1 - RX; // 5/4 значение

            DrawHack.DrawSymmetric(bitmap, center, x, y, color);
            DrawHack.DrawSymmetric(bitmap, center, y, x, color);

            while (x < y)
            {
                x++;
                if (p < 0) // выбираем правый
                {
                    p += 2 * x + 1;
                }
                else // выбираем диагональный
                {
                    y--;
                    p += 2 * (x - y) + 1;
                }

                DrawHack.DrawSymmetric(bitmap, center, x, y, color);
                DrawHack.DrawSymmetric(bitmap, center, y, x, color);
            }
        }
Ejemplo n.º 3
0
        public static void DrawEllipse(Bitmap bitmap, Point center, int a, int b, Color color)
        {
            double angle = 0;

            int x = a, y = 0;
            int aa = a * a;
            int bb = b * b;

            int y_dot = (int)Math.Round(bb / Math.Sqrt(aa + bb)); // точка перегиба

            // 1 октанта
            double step = 1 / (double)b;

            while (y <= y_dot)
            {
                x = Convert.ToInt32(a * Math.Cos(angle));
                y = Convert.ToInt32(b * Math.Sin(angle));

                DrawHack.DrawSymmetric(bitmap, center, x, y, color);

                angle += step;
            }

            // 2 октанта
            step = 1 / (double)a;
            while (x > 0)
            {
                x = Convert.ToInt32(a * Math.Cos(angle));
                y = Convert.ToInt32(b * Math.Sin(angle));

                DrawHack.DrawSymmetric(bitmap, center, x, y, color);

                angle += step;
            }
        }
Ejemplo n.º 4
0
        public static void DrawEllipse(Bitmap bitmap, Point center, int a, int b, Color color)
        {
            int aa  = a * a;
            int bb  = b * b;
            int bb2 = 2 * bb;
            int aa2 = 2 * aa;

            int rdel2 = (int)(aa / Math.Sqrt(aa + bb)); //производная для ограничения


            int x = 0;
            int y = b;

            int df = 0;
            int f  = (int)(bb - aa * y + 0.25 * aa + 0.5);

            int delta = -aa2 * y;

            for (x = 0; x <= rdel2; x++)
            {
                DrawHack.DrawSymmetric(bitmap, center, x, y, color);

                if (f >= 0)
                {
                    y     -= 1;
                    delta += aa2;
                    f     += delta;
                }
                df += bb2;;
                f  += df + bb;
            }

            delta = bb2 * x;
            f    += (int)(-bb * (x + 0.75) - aa * (y - 0.75));
            df    = -aa2 * y;

            for (; y >= 0; y--)
            {
                DrawHack.DrawSymmetric(bitmap, center, x, y, color);

                if (f < 0)
                {
                    x     += 1;
                    delta += bb2;
                    f     += delta;
                }
                df += aa2;
                f  += df + aa;
            }
        }
Ejemplo n.º 5
0
        // Нарисовать окружность
        public static void DrawCircle(Bitmap b, Point center, int radius, Color color)
        {
            int    x = 0, y;
            int    rr    = radius * radius;
            double halfR = radius / Math.Sqrt(2);

            for (x = 0; x <= halfR; x++)
            {
                y = Convert.ToInt32(Math.Sqrt(rr - x * x));

                DrawHack.DrawSymmetric(b, center, x, y, color);
                DrawHack.DrawSymmetric(b, center, y, x, color);
            }
        }
Ejemplo n.º 6
0
        public static void DrawCircle(Bitmap b, Point center, int radius, Color color)
        {
            double t = 0, step = 1 / (float)radius;
            int    x, y;

            for (t = 0; t < Math.PI / 4; t += step)
            {
                x = Convert.ToInt32(radius * Math.Cos(t));
                y = Convert.ToInt32(radius * Math.Sin(t));

                DrawHack.DrawSymmetric(b, center, x, y, color);
                DrawHack.DrawSymmetric(b, center, y, x, color);
            }
        }
Ejemplo n.º 7
0
        public static void DrawEllipse(Bitmap bitmap, Point center, int a, int b, Color color)
        {
            int aa = a * a; //a^2
            int bb = b * b; //b^2
            int bb2 = 2 * bb;
            int aa2 = 2 * aa;
            int x = 0, y = b;
            //f(x,y)=x^2*b^2+a^2y^2-a^2*b^2=0 из каноического

            //error=b^2*(x+1)^2 + a^2*(y-1)^2-a^2*b^2=
            int d = aa + bb - aa2 * y;
            int d1, d2;

            while (y >= 0)
            {
                DrawHack.DrawSymmetric(bitmap, center, x, y, color);

                if (d == 0) // диагональная точка лежит на окружности
                {
                    DiagonalStep(ref x, ref y, ref d, aa, aa2, bb, bb2);
                }
                else if (d < 0) //диагональная точка внутри окружности
                {
                    d1 = 2 * d + y * aa2 - aa;
                    if (d1 > 0)
                    {
                        DiagonalStep(ref x, ref y, ref d, aa, aa2, bb, bb2);
                    }
                    else
                    {
                        HorizontalStep(ref x, ref d, bb, bb2);
                    }
                }
                else // диагональная точка вне окружности
                {
                    d2 = 2 * d - bb2 * x - bb;
                    if (d2 < 0)
                    {
                        DiagonalStep(ref x, ref y, ref d, aa, aa2, bb, bb2);
                    }
                    else
                    {
                        VerticalStep(ref y, ref d, aa, aa2);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static void DrawCircle(Bitmap b, Point center, int radius, Color color)
        {
            int x = 0, y = radius;

            int d = 2 * (1 - radius); // первоначальная ошибка
            int d1, d2;

            double halfR = radius / Math.Sqrt(2);

            for (x = 0; x <= halfR;)
            {
                DrawHack.DrawSymmetric(b, center, x, y, color);
                DrawHack.DrawSymmetric(b, center, y, x, color);

                if (d == 0) // диагональная точка лежит на окружности
                {
                    DiagonalStep(ref x, ref y, ref d);
                }
                else if (d < 0) //диагональная точка внутри окружности
                {
                    d1 = 2 * d + 2 * y - 1;
                    if (d1 > 0)
                    {
                        DiagonalStep(ref x, ref y, ref d);
                    }
                    else
                    {
                        HorizontalStep(ref x, ref d);
                    }
                }
                else // диагональная точка вне окружности
                {
                    d2 = 2 * d - 2 * x - 1;
                    if (d2 < 0)
                    {
                        DiagonalStep(ref x, ref y, ref d);
                    }
                    else
                    {
                        VerticalStep(ref y, ref d);
                    }
                }
            }
        }