[A89] ellipses again


[Prev][Next][Index][Thread]

[A89] ellipses again




I finally figured out that the problem with the algorithm was overflow, and that changing the
variables to long int instead of int fixes it.  I've been playing around with another algorithm I
found with less multiplication, but it seems to be slower.  
The bresenham algorithm is kinda slow, but it does get the ellipse right.  The speed also is not
too obvious for smaller sizes.  All filling attributes work except for XOR.  This is not much of a
problem for me now, but I don't like leaving it with something that doesn't work.  The function
seems to create some overlap, which affects nothing but XOR.  If anyone has any suggestions as to
how to get rid of this without slowing it down too much, they would be very welcome.

thanks,
jeff

void symmetry(int x, int y, int cx, int cy, short Attr)
{
 DrawLine(cx+x,cy+y,cx+x,cy-y,Attr);  
 DrawLine(cx-x,cy+y,cx-x,cy-y,Attr);
}

void bresenham_ellipse(int a, int b, int cx, int cy, short Attr)
{
 long int S, T,a2,b2;
 int x,y;

 a2 = a*a;
 b2 = b*b;
 x = 0;
 y = b;
 S = a2*(1-2*b) + 2*b2;
 T = b2 - 2*a2*(2*b-1);
 symmetry(x,y,cx,cy,Attr);
 do
   {
    if (S<0)
       {
        S += 2*b2*(2*x+3);
        T += 4*b2*(x+1);
        x++;
       }
      else if (T<0)
          {
           S += 2*b2*(2*x+3) - 4*a2*(y-1);
           T += 4*b2*(x+1) - 2*a2*(2*y-3);
           x++;
           y--;
          }
         else
          {
           S -= 4*a2*(y-1);
           T -= 2*a2*(2*y-3);
           y--;
          }
    symmetry(x,y,cx,cy,Attr);
   }
 while (y>0);
}

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Follow-Ups: