Professional Documents
Culture Documents
Chapter 2 CGR
Chapter 2 CGR
POLYTECHNIC, KOPARGAON
With NBA ACCREDIATED programs , Approved by AICTE, New Delhi,
Recognized by Govt. of Maharashtra, Affiliated to Maharashtra State Board of Technical Education, Mumbai,
ISO 9001:2015 Certified Institute
0 2 2 (2,2)
1 3 3 (3,3)
2 4 4 (4,4)
3 5 5 (5,5)
4 6 6 (6,6)
0 1 1 (1,1)
1
1
1.5
(1,2)
2 3 2 (3,2)
3
4
2.5
(4,3)
4 5 3 (5,3)
0
1
1
(1,1)
1 1.8 2 (1.8,2)
2 2.6 3 (2.6,3)
3
3.4
4
(3.4,4)
4 4.2 5 (4.2,5)
5 5 6 (5,6)
Initialize
graphics function initgraph (&gd, &gm, "");
int X0 = 2, Y0 = 2, X1 = 14, Y1 = 16;
DDA(2, 2, 14, 16);
return 0;
}
1. Read the line end points (x1,y1) and (x2,y2) such that they are not equal.
[if equal then plot that point and exit]
2. Δx = |x2 - x1| and Δy = |y2-y1|
3. [initialize starting point]
x=x1
y=y1
4.Pk= 2 * Δy - Δx
[Initialize value of decision variable or error to compensate for nonzero intercepts]
5.i= 1 [Initialization counter]
6. Plot (x,y)
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
7. While (Pk ≥ 0)
{
y=y+1
Pk=Pk+2Δy-2*Δx
}
x= x+1
Pk=Pk+2*Δy
8. i= i+1
9.if (i ≤ Δx) then go to step 6.
10. Stop.
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
Problem: - Consider the line from (5, 5) to (13, 9). Use Bresenham's algorithm to
rasterize the line.
Solution :-
Evaluating steps 1 through 4 in the Bresenham’s algorithm we have,
Given: -
step 1 :- x1 = 5 , y1 = 5 and x2 = 13 , y2 = 9 .
step 2 :- Δx = | 13 - 5| =8 Δy = | 9 - 5 | = 4
step 3 :- x = 5 , y = 5
step 4 :- Pk = 2 * Δy - Δx = 2 * 4 - 8 = 0 .
Tabulating the results of each iteration in the step 5 through 10.
Sanjivani K.B.P. Polytechnic, Kopargaon Department of Computer Engg A. L. Deokate
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
2.Plot a line by using Bresenham's line generating algorithm from (1, 1) to (5, 3).
1.calcualte Δx and Δy
Δx=x2-x1 & Δy=y2-y1
Δx=5-1=4 & Δy=3-1=2
2.Calculating Decision Variable
Pk= 2*Δy-Δx , Pk= 2*2-4=0
3. Initialize value of e=0 starting coordinate of graph are x1,y1(1,1)
4. Here dx =4 =steps
5. Check condition e>=0
y=y+1 or y=1+1=2
Pk=Pk-2*Δx or Pk=0-2*4 =-8
Finally x get incremented x=x+1 or x=1+1=2
1.Symmetry of circle:-
1.A circle is a geometric figure which is round, and can be divided into
360 degrees. A circle is a symmetrical figure which follows 8-way
symmetry.
8-Way symmetry: Any circle follows 8-way symmetry. This means that
for every point (x,y) 8 points can be plotted. These (x,y), (y,x), (-y,x), (x,-
y), (-x,-y), (-y,-x), (y,-x), (-x, y).
For any point (x+a, y+b), points (x ± a, y ± b) and (y ± a, x ± b) also lie on
the same circle. So it is sufficient to compute only 1/8 of a circle, and all
the other points can be computed from it.
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
Sanjivani K.B.P. Polytechnic, Kopargaon Department of Computer Engg A. L. Deokate
Drawing a circle: To draw a circle we need two things, the coordinates
of the centre and the radius of
the circle.
Radius: The radius of a circle is the length of the line from the centre to
any point on its edge.
Equation of the circle: For any point on the circle (x,y) and the centre at
point (x c ,y c ), the equation of the
circle is
(x-x c ) 2 + (y-y c ) 2 - r 2 = 0
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
Here r is the radius of the circle. If the circle has origin (0,0) as its centre then the above equation
can be
reduced to
x2+y2=r2
Defining a circle using Polynomial Method:
The first method defines a circle with the second-order polynomial equation as shown in fig:
y 2 =r 2 -x 2
Where x = the x coordinate
y = the y coordinate
r = the circle radius
With the method, each x coordinate in the sector, from 90° to 45°, is found by stepping x from 0
to & each y coordinate is found by evaluating for each step of x.
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
Bresenham’s circle drawing algorithm
• It is not easy to display a continuous smooth arc on the computer screen as our
computer screen is made of pixels organized in matrix form. So, to draw a circle on a
computer screen we should always choose the nearest pixels from a printed pixel so as
they could form an arc. There are two algorithm to do this:
• Both of these algorithms uses the key feature of circle that it is highly symmetric. So, for
whole 360 degree of circle we will divide it in 8-parts each octant of 45 degree. In order
to that we will use Bresenham’s Circle Algorithm for calculation of the locations of the
pixels in the first octant of 45 degrees. It assumes that the circle is centered on the
origin. So for every pixel (x, y) it calculates, we draw a pixel in each of the 8 octants of
the circle as shown below :
• Now, we will see how to calculate the next pixel location from a previously known pixel
location (x, y). In Bresenham’s algorithm at any point (x, y) we have two options either
to choose the next pixel in the east i.e. (x+1, y) or in the south east i.e. (x+1, y-1).
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
• And this can be decided by using the decision parameter d as:
• If d > 0, then (x+1, y-1) is to be chosen as the next pixel as it will be closer to
the arc.
• else (x+1, y) is to be chosen as the next pixel.
• Now to draw the circle for a given radius ‘r’ and centre (xc, yc) We will start
from (0, r) and move in first quadrant till x=y (i.e. 45 degree). We should
start from listed initial condition:
d = 3 - (2 * r)
x=0
y=r
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
Bresenham's Circle Drawing Algorithm
Algorithm to plot ⅛ of the circle using bresenham’s algorithm.
1.Read the radius (r) of the circle.
2.d= 3-2r
[Initialize the decision variable]
3.x=0 ,y=r
[Initialize starting points]
1 0 10 -17
2 1 10 -11
3 2 10 -1
4 3 10 13
5 4 9 -5
6 5 9 17
7 6 8 11
8 7 7 13
1 0 3 -3
2 1 3 3
3 2 2 5
BASIS FOR
BOUNDARY-FILL
COMPARIS FLOOD-FILL ALGORITHM
ALGORITHM
ON
consumption
complexity
• The term pixel is a short form of the picture element. It is also called a
point or dot. It is the smallest picture unit accepted by display devices. A
picture is constructed from hundreds of such pixels. Pixels are generated
using commands. Lines, circle, arcs, characters; curves are drawn with
closely spaced pixels. To display the digit or letter matrix of pixels is used.
• The closer the dots or pixels are, the better will be the quality of picture.
Closer the dots are, crisper will be the picture. Picture will not appear
jagged and unclear if pixels are closely spaced. So the quality of the
picture is directly proportional to the density of pixels on the screen.
• Pixels are also defined as the smallest addressable unit or element of the
screen. Each pixel can be assigned an address as shown in fig:
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
Sanjivani K.B.P. Polytechnic, Kopargaon Department
of Computer Engg A. L. Deokate
• Different graphics objects can be generated by setting the different intensity of
pixels and different colors of pixels. Each pixel has some co-ordinate value. The
coordinate is represented using row and column. P (5, 5) used to represent
a pixel in the 5th row and the 5th column. Each pixel has some intensity value
which is represented in memory of computer called a frame buffer.Frame Buffer
is also called a refresh buffer. This memory is a storage area for storing pixels
values using which pictures are displayed. It is also called as digital memory.
Inside the buffer, image is stored as a pattern of binary digits either 0 or 1. So
there is an array of 0 or 1 used to represent the picture. In black and white
monitors, black pixels are represented using 1's and white pixels are represented
using 0's. In case of systems having one bit per pixel frame buffer is called a
bitmap. In systems with multiple bits per pixel it is called a pixmap.