top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to draw a circle without use of floating point computation?

+7 votes
757 views

Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all ??

posted Oct 29, 2013 by Mona Sharma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Use Mid Point Circle Algorithm

public static void DrawCircle(int x0, int y0, int radius)
{
  int x = radius, y = 0;
  int radiusError = 1-x;

  while(x >= y)
  {
    DrawPixel(x + x0, y + y0);
    DrawPixel(y + x0, x + y0);
    DrawPixel(-x + x0, y + y0);
    DrawPixel(-y + x0, x + y0);
    DrawPixel(-x + x0, -y + y0);
    DrawPixel(-y + x0, -x + y0);
    DrawPixel(x + x0, -y + y0);
    DrawPixel(y + x0, -x + y0);

    y++;
    if(radiusError<0)
            radiusError+=2*y+1;
    else
    {
            x--;
            radiusError+=2*(y-x+1);
    }
  }
}
answer Oct 29, 2013 by Salil Agrawal
Similar Questions
+4 votes

If we delete the mth number from a circle which is composed of numbers 0, 1, …, n-1 counting from 0 at every time, what is the last number?

For example, a circle is composed of five numbers 0, 1, 2, 3, 4. If we delete the 3rd number at every time, the deleted numbers are in order of 2, 0, 4, 1, so the last remaining number is 3.

+3 votes

How to find shortest path in a multistage graph using dynamic programming, C/C++ code would be helpful?

0 votes

Suppose I have been given an array and I need to findout all such combination where a^2 + b^2 = c^2 then how can I achieve that?

C/C++ code would be helpful?

...