コード例 #1
0
        public override void draw_DDA(DrawPixelFunc setPixel)
        {
            int dx = x1 - x0, dy = y1 - y0, steps, k;

            double xIncrement, yIncrement, x = x0, y = y0;

            if (Math.Abs(dx) > Math.Abs(dy))
            {
                steps = Math.Abs(dx);
            }
            else
            {
                steps = Math.Abs(dy);
            }

            xIncrement = dx / (double)steps;
            yIncrement = dy / (double)steps;

            for (k = 0; k < steps; k++)
            {
                setPixel(Round(x), Round(y));
                x += xIncrement;
                y += yIncrement;
            }
        }
コード例 #2
0
        public override void draw_DDA(DrawPixelFunc setPixel)
        {
            int    a = halfBigAxis;
            int    b = halfSmallAxis;
            int    x, y;
            double tmp;
            //0 = b2x2 + a2y2 -a2b2

            double xEnd = a * a / Math.Sqrt(a * a + b * b);
            double yEnd = b * b / Math.Sqrt(a * a + b * b);

            for (x = 0; x <= xEnd; x++)
            {
                tmp = (a * a * b * b - b * b * x * x) / (a * a);
                y   = Round(Math.Sqrt(tmp));
                set4pixel(setPixel, x, y);
            }

            for (y = 0; y <= yEnd; y++)
            {
                tmp = (a * a * b * b - a * a * y * y) / (b * b);
                x   = Round(Math.Sqrt(tmp));
                set4pixel(setPixel, x, y);
            }
        }
コード例 #3
0
 public void set4pixel(DrawPixelFunc setPixel, int x, int y)
 {
     setPixel(x0 + x, y0 + y);
     setPixel(x0 - x, y0 + y);
     setPixel(x0 + x, y0 - y);
     setPixel(x0 - x, y0 - y);
 }
コード例 #4
0
        public override void draw_MidPoint(DrawPixelFunc setPixel)
        {
            int x, y;

            x = 0;
            y = radius;

            set8pixel(setPixel, x, y);
            double p = 1 - radius;

            while (x < y)
            {
                if (p < 0)
                {
                    p += 2 * x + 3;
                }
                else
                {
                    p += 2 * (x - y) + 5;
                    y--;
                }
                x++;
                set8pixel(setPixel, x, y);
            }
        }
コード例 #5
0
        public override void draw_MidPoint(DrawPixelFunc setPixel)
        {
            int a = halfBigAxis;
            int b = halfSmallAxis;

            int x, y, fx, fy, a2, b2, p;

            x  = 0;
            y  = b;
            a2 = a * a;
            b2 = b * b;
            fx = 0;
            fy = 2 * a2 * y;

            set4pixel(setPixel, x, y);

            p = Round(b2 - (a2 * b) + (0.25 * a2));//p=b2 - a2*b +a2/4
            while (fx < fy)
            {
                x++;
                fx += 2 * b2;

                if (p < 0)
                {
                    p += b2 * (2 * x + 3);//p=p + b2*(2x +3)
                }
                else
                {
                    y--;
                    p  += b2 * (2 * x + 3) + a2 * (2 - 2 * y);//p=p +b2(2x +3) +a2(2-2y)
                    fy -= 2 * a2;
                }
                set4pixel(setPixel, x, y);
            }
            p = Round(b2 * (x + 0.5) * (x + 0.5) + a2 * (y - 1) * (y - 1) - a2 * b2);
            //
            while (y > 0)
            {
                y--;
                fy -= 2 * a2;

                if (p >= 0)
                {
                    p += a2 * (3 - 2 * y); //p=p +a2(3-2y)
                }
                else
                {
                    x++;
                    fx += 2 * b2;
                    p  += b2 * (2 * x + 2) + a2 * (3 - 2 * y);//p=p+ b2(2x +2) + a2(3-2y)
                }
                set4pixel(setPixel, x, y);
            }
        }
コード例 #6
0
        public override void draw_DDA(DrawPixelFunc setPixel)
        {
            int    x, y;
            double xEnd = radius / Math.Sqrt(2);

            for (x = 0; x < xEnd; x++)
            {
                y = radius * radius - x * x;
                y = (int)(Math.Sqrt(y) + 0.5);

                set8pixel(setPixel, x, y);
            }
        }
コード例 #7
0
        public override void draw_Bresenham(DrawPixelFunc setPixel)
        {
            int xA = x0, yA = y0, xB = x1, yB = y1;
            int dx    = Math.Abs(xA - xB);
            int dy    = Math.Abs(yA - yB);
            int steep = (dy > dx) ? 1 : 0;

            if (steep == 1)
            {
                swap(ref dx, ref dy);
                swap(ref xA, ref yA);
                swap(ref xB, ref yB);
            }
            if (dx == 0 && dy == 0)
            {
                setPixel(xA, yA);
                return;
            }

            int p  = 2 * dy - dx;
            int d1 = 2 * dy;
            int d2 = 2 * (dy - dx);

            int xInc = (xA < xB) ? 1 : -1;
            int yInc = (yA < yB) ? 1 : -1;

            while (xA != xB)
            {
                if (steep == 1)
                {
                    setPixel(yA, xA);
                }
                else
                {
                    setPixel(xA, yA);
                }
                if (p < 0)
                {
                    p += d1;
                }
                else
                {
                    p  += d2;
                    yA += yInc;
                }
                xA += xInc;
            }
        }
コード例 #8
0
        public override void draw_MidPoint(DrawPixelFunc setPixel)
        {
            int a  = realAxis;
            int b  = virtualAxis;
            int p  = 0;
            int x  = a;
            int y  = 0;
            int a2 = a * a;
            int b2 = b * b;

            p = (int)(1.0 * b2 / 4 + a * b2 - a2);

            int end = (int)((a <= b ? height : b * b / Math.Sqrt(a2 - b2)));

            while (y < end)
            {
                set4pixel(setPixel, x, y);

                if (p < 0)
                {
                    p += (2 * x + 2) * b2 - (2 * y + 3) * a2;
                    x++;
                }
                else
                {
                    p -= a2 * (2 * y + 3);
                }
                y++;
            }

            p = b2 - a2 / 4;
            while (x < width)
            {
                set4pixel(setPixel, x, y);

                if (p < 0)
                {
                    p += (x + 1) * 2 * b2;
                }
                else
                {
                    p += (x + 1) * 2 * b2 - (2 * y + 2) * a2;
                    y++;
                }
                x++;
            }
        }
コード例 #9
0
        public override void draw_DDA(DrawPixelFunc setPixel)
        {
            double a = hs_a;

            if (hs_a < 0)
            {
                a = -a;
            }
            int    x, y;
            double xEnd   = 1 / (2 * a);
            double yStart = 1 / (4 * a);

            for (x = 0; x < xEnd; x++)
            {
                y = (int)(a * x * x + 0.5);

                if (hs_a < 0)
                {
                    set2PixelWithANegative(setPixel, x, y);
                }
                else
                {
                    set2Pixel(setPixel, x, y);
                }
            }

            for (y = (int)yStart; y <= height; y++)
            {
                x = (int)(Math.Sqrt(y / a) + 0.5);
                if (hs_a < 0)
                {
                    set2PixelWithANegative(setPixel, x, y);
                }
                else
                {
                    set2Pixel(setPixel, x, y);
                }
            }
        }
コード例 #10
0
        public override void draw_DDA(DrawPixelFunc setPixel)
        {
            int    a = realAxis;
            int    b = virtualAxis;
            int    x, y;
            double xStart = (a > b) ? a * a / Math.Sqrt(a * a - b * b) : a * a / Math.Sqrt(b * b - a * a);
            double yEnd   = (a > b) ? b * b / Math.Sqrt(a * a - b * b) : b * b / Math.Sqrt(b * b - a * a);
            double tmp;

            for (y = 0; y <= yEnd; y++)
            {
                tmp = (a * a * y * y + a * a * b * b) / (b * b);
                x   = (int)(Math.Sqrt(tmp) + 0.5);
                set4pixel(setPixel, x, y);
            }

            for (x = (int)xStart; x <= width; x++)
            {
                tmp = (b * b * x * x - a * a * b * b) / (a * a);
                y   = (int)(Math.Sqrt(tmp) + 0.5);
                set4pixel(setPixel, x, y);
            }
        }
コード例 #11
0
        public override void draw_MidPoint(DrawPixelFunc setPixel)
        {
            int a, b, c, xA = x0, yA = y0, xB = x1, yB = y1, p;

            int steep = (Math.Abs(y1 - y0) > Math.Abs(x1 - x0)) ? 1 : 0;

            if (steep == 1)
            {
                swap(ref xA, ref yA);
                swap(ref xB, ref yB);
            }

            a = yB - yA;
            b = -(xB - xA);
            c = xB * yA - xA * yB;

            int xInc = (xA < xB) ? 1 : -1;
            int yInc = (yA < yB) ? 1 : -1;

            while (xA != xB)
            {
                if (steep == 1)
                {
                    setPixel(yA, xA);
                }
                else
                {
                    setPixel(xA, yA);
                }
                xA += xInc;
                if ((2 * a * xA + 2 * b * yA + 2 * c + 2 * a + b) >= 0)
                {
                    yA += yInc;
                }
            }
        }
コード例 #12
0
 public abstract void draw_MidPoint(DrawPixelFunc func);
コード例 #13
0
 public abstract void draw_DDA(DrawPixelFunc func);
コード例 #14
0
 public override void draw_Bresenham(DrawPixelFunc func)
 {
     throw new NotImplementedException();
 }
コード例 #15
0
 public abstract void draw_Bresenham(DrawPixelFunc func);
コード例 #16
0
        public override void draw_MidPoint(DrawPixelFunc setPixel)
        {
            double a          = hs_a;
            int    isNegative = 0;

            if (a == 0)
            {
                return;
            }
            if (a < 0)
            {
                isNegative = 1;
                a          = -a;
            }
            int    x = 0, y = 0;
            double f = 2 * a - 1;

            set2Pixel(setPixel, x, y);

            while (2 * a * x < 1)
            {
                if (f < 0)
                {
                    f = f + a * (2 * x + 3);
                }
                else
                {
                    f = f + a * (2 * x + 3) - 1;
                    y++;
                }
                x++;
                if (isNegative == 0)
                {
                    set2Pixel(setPixel, x, y);
                }
                else
                {
                    set2PixelWithANegative(setPixel, x, y);
                }
            }
            x = round(0.5 / a);
            y = round(0.25 / a);

            f = a - 2;
            set2Pixel(setPixel, x, y);
            while (y <= height)
            {
                if (f < 0)
                {
                    f = f + 2 * a * (x + 1) - 1;
                    x++;
                }
                else
                {
                    f--;
                }
                y++;
                if (isNegative == 0)
                {
                    set2Pixel(setPixel, x, y);
                }
                else
                {
                    set2PixelWithANegative(setPixel, x, y);
                }
            }
        }
コード例 #17
0
 public void set2PixelWithANegative(DrawPixelFunc setPixel, int x, int y)
 {
     setPixel(x0 + x, y0 - y);
     setPixel(x0 - x, y0 - y);
 }