# العام الدراسي 1436- 1437 ```Scan Conversion of Line Segments
What is Scan conversion?
 Final step of rasterization (the process of taking geometric




shapes and converting them into array of pixels stored in the
frame buffer to be displayed )
Take place after clipping accurs .
All graphics package do this at end of rendering pipeline
Take triangles and maps them to pixels on the screen
Also take into account other properties like lighting and
shading ,but we will focus on first on algorithm for line scan
conversion.
Design criteria of straight lines
 What is the key issues of drawing a line ?
 Find the addressable pixels which most closely approximate




this line .
Straight line should appear straight .
Line should start and end accurately matching end points
with connecting lines.
Lines should have constant brightness.
Lines should be drawn as rapidly as possible.
.
 Problem
 Others create problems:
Stair casing
Aliasing
 Quality of the line depend on the location of the pixels and
their brightness.
Direct solution to draw a line
 Y=mx+b , where (0,b) is the y intercept and m is the slope
 Go from x0 to x1:
calculate round (y) from the equation
 Take an example b=1(starting point (0,1)) and m =3/5
 Then x=1 ,y=2= round(8/5)
x=2 ,y=2= round(11/5)
x=3 ,y=3= round(14/5)
x=4 ,y=3= round(17/5)
x=5 ,y=4= round(20/5)

.
Direct solution to draw a line
 The line we draw must be straight .
 Why when we see line in the screen we always see it straight?
 Because we see a line in a high resolution graphic monitor
and that monitor may have a thousands pixels .
 Another problem how fast we can draw the line ?
Why we use round ?
Direct solution to draw a line
 Why the round function is important?
 Because there is no addressable pixels available at any
arbitrary floating number so you will use the next highest
number and next lowest number .
 Why is this undesired ?
 Operators like ‘*’ and ‘/’ are expensive .
 Round function needed .
 Can get gap in the line ( if the slope &gt;1).
 Another example :
 Y=10.x+2


x1=1, y1=12;
X2=2 ,y2=22.
DDA Algorithm
 Digital Differential Analyzer
 Incremental algorithm
 DDA was a mechanical device for numerical solution of
differential equations.
 Based on y =(y1-y0)/(x1-x0) x+ b
 Assume x1&gt; x0 and
dx &gt; dy
(Can easily be modifeid for the other cases )
dx=x1-x0;
dy=y1-y0;
m=dy/dx;
y=y0;
13
.
 The algorithm
For (x=x0 to x1)
Draw_point(x,round(y));
Y=y+m;
End for
.
 Problem
 There are still two costly functions one is the round
operation and the second is the floating point addition .
 How can we get rid of these?
 If we can eliminate the round function and replace the
floating addition by integer ,the algorithm will be several
times faster .
 DDA is not the most efficient one .
.
 We assume that we are drawing a line from the left to the
right ,the slope is less than one.
 There are 8 octants, we solve the algorithm in the first one .
Bresenham’s Algorithm
 Also called Midpoint Line Algorithm.
 Incremental algorithm (assume first octant).
 It is commonly used to draw lines on a computer screen, as it
uses only integer addition, subtraction and bit shifting, all of
which are very cheap operations in standard computer
architectures.
 It is one of the earliest algorithms developed in the field of
computer graphics. A minor extension to the original
algorithm also deals with drawing circles.
.
 Given the choice of the current pixel ,which one do we






choose next :E or NE ?
Equation:
Y= (dy/dx)*x+B
Rewrite As :
F(x,y)=a*x+b*y+c=0
Gives :f(x,y)=dy*x-dx*y+B*dx=0
=&gt; a=dy , b=-dx , c=B*dx
.
 The equation of the line is
 F(x,y)=dy*x-dx*y+B*dx=0
 If f(x,y)&gt;0 if the point below the line
 If f(x,y)&lt;0 if the point above the line
.
 If you take a point which is exactly on the line and substitute
it in the equation the value of f(x,y) will be equal to zero.
 IF you substitute a value of a point which is on the top or the
bottom of the line , then you will get the value of f(x,y) not
equal to zero.
Hidden Surface Removal
 Object-space approach: use pairwise testing between polygons
(objects)
partially obscuring
21
can draw independently
Painter’s Algorithm
 Also known as a priority fill, is one of the simplest
solutions to the visibility problem in 3D computer graphics.
When projecting a 3D scene onto a 2D plane, it is necessary
at some point to decide which polygons are visible, and
which are hidden.
22
```