Page 62 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 62
Lab on Computer Graphics
Notes 4. Choose the next pixel depending on the value of p n . If p n < 0, choose pixel (x n + 1, y n ), if
p n > 0, choose pixel (x n + 1, y n – 1), and if p n = 0, choose either pixel.
5. If you chose pixel (x n + 1, y n ), determine the next pixel from the sign of (x n + 2, y n – ½)
denoted by p n +1:
P n +1 = g(x n +2, y n –1/2)
2
2
= (x n +2) + (y n –1/2) – R 2
=> The increment in p is Δp 1 = p n +1 – p n = 2x + 3.
If you choose pixel (x n +1, y n –1), determine the next pixel from the sign of (x n +2, – 3/2 )
denoted by p n +1:
P n +1 = g (x n +2, y n –3/2)
2
= (x n +2) + (y n –3/2) – R 2
2
=> The increment in p is Δp 2 = p n +1 – p n = 2x n – 2y n + 5.
6. Calculate the initial condition, p 0 . The first point on the circle is (0, R) and the first midpoint
D is at (1, R – ½). Calculate p 0 as:
=> p 0 = g(1, R – ½)
= 12 + (R – ½) – R 2
2
= 5/4 – R.
If all the attributes of the circle, such as the centre coordinates and the radius, are given
as integers, you can round p 0 to p 0 = 1 – R.
7. To draw the circle, start with the pixel (0, R) and initialize p to 0.
After plotting the pixel (0, R), increment the value of p by p 0 . For subsequent pixels, determine
the next pixel depending upon the value of p. If p < 0, choose (x n +1, y n ) as the next pixel and
increment p by Δp 1 . If p > 0, choose pixel (x n +1, y n +1) and increment p by Δp 1 . If p = 0, choose
either. Plot the pixels on the circumference of the circle up to x = R/√2 or y < x. For each pixel
calculated, use the symmetry () function to obtain all the symmetric pixels.
4.2.2 Implement Midpoint Circle Drawing Algorithm in C
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void draw_circle(int, int, int);
void symmetry(int, int, int, int);
main()
{
int x c , y c , R;
int driver, mode;
clrscr();
printf(“Enter the center of the circle:\n”);
printf(“Xc =”);
scanf(“%d”, &xc);
printf(“Yc =”);
scanf(“%d”, &y c );
56 LOVELY PROFESSIONAL UNIVERSITY