Computer Graphics
Computer Graphics
for calculation of the locations of the pixels in the first octant of 45 degrees. It
assumes that the circle is centred on the origin. So for every pixel (x, y) it
calculates, we draw a pixel in each of the 8 octants of the circle.
The points generation using Bresenham Circle Drawing Algorithm involves the
following steps-
Step # 1:
Assign the starting point coordinates (X, Y) as-
● X=0
● Y=R
Step # 2:
Calculate the value of initial decision parameter P as-
P= 3 – 2 R
Step # 3:
Suppose the current point is (Xi, Yi) and the next point is (Xi+1, Yi+1).
Find the next point of the first octant depending on the value of decision
parameter Pi.
Follow the below two cases:
if(p<0){
Xi+1 = Xi + 1
Yi+1 = Yi
Pi+1 = Pi + 4.Xi+1 + 6
}
if(P>=0)
{
Xi+1 = Xi + 1
Yi+1 = Yi -1
Pi+1 = Pi + 4(Xi+1 - Yi+1 ) + 10
}
Step # 4:
Keep repeating Step-02 and Step-03 until Xi+1 >= Yi+1
Step # 5:
Step-04 generates all the points for one octant.
To find the points for the other seven octants for all Quadrants from 90 degree
to 45 degree, follow the eight symmetry property of the circle.
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
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, "C:\\TURBOC3\\BGI");
getch();
closegraph();
return 0;
}
Output
It is based on the following function for testing the spatial relationship between
the arbitrary point (x, y) and a circle of radius r centred at the origin
Now,
yi+1 = yi
xi+1 = xi + 1
Put these values in Pi+1 = Pi + 2(xi + 1) + (y2 i+1 - yi2) -( yi+1 - yi) + 1
= Pi + 2xi + 2 + 1
Pi+1 = Pi + 2xi + 3
If the case is
yi+1 = yi - 1
xi+1 = xi + 1
Put these values in Pi+1 = Pi + 2(xi + 1) + (y2 i+1 - yi2) -( yi+1 - yi) + 1
= Pi + 2xi + 2 - 2yi + 1 + 2
At initial
X = 0, y = R
Pi=(xi+1)2+(yi- )2- r2
= (0 + 1) 2 + ( r - ½)2 - r2
= 1 + r2 + 1/ 4 -r- r2
= 1/4 + 1 - r
= 5/4 - r
As 5/4 approximately equals to 1 (5/4 ~ 1)
Pi = 1 - r
We have p=1-r
Step3: End
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
class bresen
float x, y,a, b, r, p;
public:
};
void main ()
bresen b;
b.get ();
b.cal ();
getch ();
cin>>a>>b;
cout<<"ENTER r";
cin>>r;
}
getch ();
x=0;
y=r;
p=5/4)-r;
while (x<=y)
If (p<0)
p+= (4*x)+6;
else
p+=(2*(x-y))+5;
y--;
x++;
} :
Output
PAST PAPER QUESTIONS
Question # 1:
Consider three different raster systems with resolutions 640 by 480,1280 by
1024 and 2560 by 2048 .
a) What frame size will require in byte to these systems to store 12 bits per
pixel.
b) How much storage will be required if 24 bits per pixel are to be stored?
Solution:
To solve these questions, we need to calculate the storage required for each
raster system based on the given resolutions and bits per pixel (bpp).
Formula:
Storage (in bytes)=(Resolution (width x height) in pixels×Bits per pixel (bpp)) / 8
For 12 bpp:
Question # 2:
Develop a mid point algorithm which scan converts a circle from start at pixel
location x=R, y= 0, Assume you're scan converting in the clockwise direction,
find equations, along with choices should be made for the next pixel.
Do the same derivation like mentioned in the above heading (MID POINT
ALGORITHM CIRCLE DRAWING) till this equation Pi+1 = Pi + 2xi + 2yi -
5
After this , At initial x=R, y= 0
Pi = (xi + 1)2 - ( yi - 1/2 )2 - r2
= (R + 1)2 - (0 - ½ )2 - r2
= R2 + 2R + 1 + ¼ - r2
= 2R + 1 + ¼
= 2R + 5/4 (5/4 ~ 1)
= 2R + 1