<p>The usual method is to just draw over the circle with your lines. The clock is behind the minute hand and the minute hand is behind the hour hand so the drawing order would be. Draw the clock face, then draw the minute hand, then draw the  hour hand.</p>
<p>This is the basic idea behind Z buffering.</p>
<p>Drawing the lines is basically the same idea as the circle, just write a function that draws a line it would take a start point and an end point as the parameters. Then another function figures out the start point and end points of each line based on the current time.</p>
<p>Figuring out the start and end points of the line is surprisingly simple. The start point is always the center of the circle. The end points are</p>
<pre><code>clock_size *(cos(time_rads),sin(time_rads)) 
</code></pre>
<p>Where the clock_size is the size of your clock, and time_rads is the current time converted to radians. ( time_in_hours*60 + time_in_minutes gives minutes on the clock face, 2pi radians in a circle.....)</p>

CC BY-SA 4.0
2021-06-23T11:17:43.160Z
2021-06-23T11:25:41.023Z
2021-06-23T11:25:41.023Z
pmw1234
<p>I am new to CG and I need to draw a wall clock using bresenhams circle algo . I have drawn a circle using this algo but how do I add minute and hour needle in it basically how do i add lines inside a circle ? I am using C language to code. Below is the code that i am using to draw a circle by this algo</p>
<pre class="lang-c prettyprint-override"><code>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;math.h&gt;

    void    EightWaySymmetricPlot(int xc,int yc,int x,int y)
   {
    putpixel(x+xc,y+yc,RED);
    putpixel(x+xc,-y+yc,RED);
    putpixel(-x+xc,-y+yc,RED);
    putpixel(-x+xc,y+yc,RED);
    putpixel(y+xc,x+yc,6);
    putpixel(y+xc,-x+yc,6);
    putpixel(-y+xc,-x+yc,6);
    putpixel(-y+xc,x+yc,6);
   }

    void BresenhamCircle(int xc,int yc,int r)
   {
    int x=0,y=r,d=3-(2*r);
    EightWaySymmetricPlot(xc,yc,x,y);

    while(x&lt;=y)
     {
      if(d&lt;=0)
             {
        d=d+(4*x)+6;
      }
     else
      {
        d=d+(4*x)-(4*y)+10;
        y=y-1;
      }
       x=x+1;
       EightWaySymmetricPlot(xc,yc,x,y);
      }
    }

    int  main(void)
   {
    /* request auto detection */
    int xc,yc,r,gdriver = DETECT, gmode, errorcode;
    /* initialize graphics and local variables */
     initgraph(&amp;gdriver, &amp;gmode, &quot; &quot;);

     /* read result of initialization */
     errorcode = graphresult();

      if (errorcode != grOk)  /* an error occurred */
     {
        printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode));
        printf(&quot;Press any key to halt:&quot;);
        getch();
        exit(1); /* terminate with an error code */
     }
       printf(&quot;Enter the values of xc and yc :&quot;);
       scanf(&quot;%d%d&quot;,&amp;xc,&amp;yc);
       printf(&quot;Enter the value of radius  :&quot;);
       scanf(&quot;%d&quot;,&amp;r);
       BresenhamCircle(xc,yc,r);
     getch();
     closegraph();
     return 0;
    }

</code></pre>

<algorithm><2d-graphics><pixel-graphics>
wall clock using bresenhams circle drawing algo
Nubcodes
# wall clock using bresenhams circle drawing algo

(Asked by: username_0 on 2021-06-21)

I am new to CG and I need to draw a wall clock using bresenhams circle algo . I have drawn a circle using this algo but how do I add minute and hour needle in it basically how do i add lines inside a circle ? I am using C language to code. Below is the code that i am using to draw a circle by this algo

```c
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>

    void    EightWaySymmetricPlot(int xc,int yc,int x,int y)
   {
    putpixel(x+xc,y+yc,RED);
    putpixel(x+xc,-y+yc,RED);
    putpixel(-x+xc,-y+yc,RED);
    putpixel(-x+xc,y+yc,RED);
    putpixel(y+xc,x+yc,6);
    putpixel(y+xc,-x+yc,6);
    putpixel(-y+xc,-x+yc,6);
    putpixel(-y+xc,x+yc,6);
   }

    void BresenhamCircle(int xc,int yc,int r)
   {
    int x=0,y=r,d=3-(2*r);
    EightWaySymmetricPlot(xc,yc,x,y);

    while(x<=y)
     {
      if(d<=0)
             {
        d=d+(4*x)+6;
      }
     else
      {
        d=d+(4*x)-(4*y)+10;
        y=y-1;
      }
       x=x+1;
       EightWaySymmetricPlot(xc,yc,x,y);
      }
    }

    int  main(void)
   {
    /* request auto detection */
    int xc,yc,r,gdriver = DETECT, gmode, errorcode;
    /* initialize graphics and local variables */
     initgraph(&gdriver, &gmode, " ");

     /* read result of initialization */
     errorcode = graphresult();

      if (errorcode != grOk)  /* an error occurred */
     {
        printf("Graphics error: %s\n", grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1); /* terminate with an error code */
     }
       printf("Enter the values of xc and yc :");
       scanf("%d%d",&xc,&yc);
       printf("Enter the value of radius  :");
       scanf("%d",&r);
       BresenhamCircle(xc,yc,r);
     getch();
     closegraph();
     return 0;
    }

```

**Tags:** algorithm, 2d-graphics, pixel-graphics


---

## 1 answers

### Answer by username_1 on 2021-06-23. Score: 1

The usual method is to just draw over the circle with your lines. The clock is behind the minute hand and the minute hand is behind the hour hand so the drawing order would be. Draw the clock face, then draw the minute hand, then draw the hour hand.

This is the basic idea behind Z buffering.

Drawing the lines is basically the same idea as the circle, just write a function that draws a line it would take a start point and an end point as the parameters. Then another function figures out the start point and end points of each line based on the current time.

Figuring out the start and end points of the line is surprisingly simple. The start point is always the center of the circle. The end points are

```
clock_size *(cos(time_rads),sin(time_rads)) 

```

Where the clock\_size is the size of your clock, and time\_rads is the current time converted to radians. ( time\_in\_hours\*60 + time\_in\_minutes gives minutes on the clock face, 2pi radians in a circle.....)


---

