Professional Documents
Culture Documents
L3 - Computer Graphics
L3 - Computer Graphics
L3 - Computer Graphics
primitives
353 عال
Lecture three
INTRODUCTION
Scan conversion or rasterization is the process of converting
the primitives from its geometric definition into a set of pixels that
make the primitive in image space. This technique is used to draw
shapes like line, circle, ellipse, etc. on the screen. Some of them
are discussed below
The process of representing continuous graphics objects as a
collection of discrete pixels is called scan conversion.
Drawing a Line Segment
The simplest way to represent a line segment is to have the coordinates of its
two end points. One way of drawing a line segment will be simply starting
with one end point and on the way of approaching the other, turning on
pixels.
This approach like our experience of drawing a line segment on paper, but it
poses two questions. First, on what criterion should we select a pixel? And
second, if the criterion is set, how do we efficiently select the required
pixels?
SCAN – CONVERSION OF LINES
b = y1 – m.x1
Digital Differential Analyzer (DDA) Algorithm
For slope greater than 1 ( |m| > 1), the roles of y and x are
Case 2 reversed, i.e. , y is sampled at unit intervals ((∆y = 1), this
means that Yk+1 = Yk+1 and corresponding x values are
calculated as XN = XO + 1/m Explain How ?
The value of x calculated is rounded off to the nearest integer value.
Example
Apply the DDL algorithm to find the appropriate coordinate to
draw a line between (2,1) and (5,5)
Example
Apply the DDL algorithm to find the appropriate coordinate to
draw a line between (2,1) and (5,5)
M>1
XN = XO + 1/m
Y= y+1
x R (x) y (x,y)
2 1 (2,1)
2.75 3 2 (3,2)
3.5 4 3 (4,3)
4.25 4 4 (4,4)
5 5 5 (5,5)
What will be happened if we reverse
the position of points ?
Pseudocode for DDA algorithm is as follows
8 Xk+1 = Xk+1
7
Yk+1 = ?
6
5
4
d1 d2
3
2
1
y = mx + b
0 1 2 3 4 5 6 6 7 8
How Bresenham’s Line Drawing Algorithm work
Example
Apply the Bresenham’s Line Drawing Algorithm to find the
appropriate coordinate to draw a line between (20,10) and
(30,18)
Example
Apply the Bresenham’s Line Drawing Algorithm to find the
appropriate coordinate to draw a line between (20,10) and
(30,18)
P0 = 6 >= 0 P0<= 0
Next.point = (x+1, y+1) Next.point = (x+1, y)
PN = PO + 2∆Y - 2∆X PN = PO + 2∆Y
6 6 16-10 = 6 21 11
2 6 16 20 22 12
-2 2 16 20 23 12
14 -2 16 20 24 13
10 14 16 20 25 14
6 10 16 20 26 15
2 6 16 20 27 16
-2 2 16 20 28 16
14 -2 16 20 29 17
10 14 16 20 30 18
Bresenham’s Line Drawing Algorithm
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. It can determine where to stop because when y = x, it has reached
45°
We cannot display a continuous arc on the raster display. Instead, we have to
choose the nearest pixel position to complete the arc. At any point (x,y), we
have two choices – to choose the pixel on M3(x+1,y) or the pixel M2(x+1,y-1)
SCAN – CONVERSION OF CIRCLE- Bresenham’s Algorithm
d d + (4*x) + 6 d + 4 * (x – y) + 10
H.W