drawing a Circle

This is a discussion on drawing a Circle within the C Programming forums, part of the General Programming Boards category; Oi !! Is it possible to draw circles in C language ?,... (not using graphics library).. I have pretty much ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    drawing a Circle

    Oi !!

    Is it possible to draw circles in C language ?,...
    (not using graphics library)..

    I have pretty much an idea of asking a user the Coordinates (x,y)of the "Center of the Circle,".. and then asking the "Radius"...

    I find it difficult to figure out the step by step procedures and algorithms in solving this out !

    Any Comments or Suggestions ?

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    It involves trig.

    You can't draw a circle without a graphics library. You could display ascii characters, but that would be pretty dumb for a circle.
    Code:
    for(radians=0;radians<2*pi;radians+=.1)
    {
         x=radius*cos(radians);
         y=radius*sin(radians);
          /* display code */
    }
    Away.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Revised a bit.
    Code:
    for(radians=0;radians<2*pi;radians+=.1)
    {
         newx=x+cos(radians)*radius;
         newy=y+sin(radians)*radius;
          /* display code */
    }

    This allows you to place the circle at any x,y.

    If you don't like using radians throughout the code then use euler angles and convert those to radians in your calls to cos() and sin() - angle *PI/180

    #define DEGREES_TO_RADIANS(x) ((double)x*PI/180.0)


    Circles can be drawn faster by mirroring the pixels since all circles are symmetric. Theoretically you only need to draw one 90 degree arc and the rest can be calcuated easily on the fly. This
    means that the code only needs to go from 0 to 90 degrees which is faster than 0 to 360 or 0 to 2*pi (6.????).

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You can use Bresenham's circle drawing algorithm if you'd like.

    http://www.gamedev.net/reference/art...article767.asp

    Also you don't need to do the 90 degree arc, you can do a 45 degree arc and mirror that for the 8 octants.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing a circle with ASCII character
    By bnkslo in forum C Programming
    Replies: 15
    Last Post: 04-03-2008, 01:56 PM
  2. drawing circle to console
    By golom in forum C Programming
    Replies: 2
    Last Post: 12-20-2006, 10:57 AM
  3. Drawing circle into a bitmap file
    By brokensail in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2006, 01:26 AM
  4. Drawing a circle using glut...
    By bennyho03 in forum C Programming
    Replies: 6
    Last Post: 10-18-2004, 11:06 AM
  5. Drawing a circle in a video captured frame
    By skyhigh in forum C Programming
    Replies: 2
    Last Post: 12-05-2001, 01:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21