3/24/2024
Scan Conversion a Line
Lecture 4
Scan Conversion
It is a process of representing graphics objects a
collection of pixels.
The graphics objects are continuous.
The pixels used are discrete.
Each pixel can have either on or off state.
0 is represented by pixel off and 1 is represented using
pixel on.
Using this ability graphics computer represent picture
having discrete dots.
Any model of graphics can be reproduced with a dense
matrix of dots or points.
The process of converting is also called as rasterization.
1
3/24/2024
Examples of objects which can be scan
converted
Point
Line
Sector
Arc
Ellipse
Rectangle
Polygon
Characters
Filled Regions
Pixel or Pel
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.
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.
So the quality of the picture is directly proportional to the
density of pixels on the screen.
2
3/24/2024
Address of a Pixel
Pixels are also defined as the smallest addressable unit or element of the
screen.
P (5, 5) used to represent a pixel in the 5th row and the 5th column.
Frame Buffer: 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.
bitmap: In case of systems having one bit per pixel frame buffer is called a
bitmap.
pixmap: In systems with multiple bits per pixel it is called a pixmap.
3
3/24/2024
Scan Converting a Straight Line
A straight line may be defined by two endpoints & an
equation.
The two endpoints are described by (x1,y1) and
(x2,y2).
The equation of the line is used to determine the x, y
coordinates of all the points that lie between these
two endpoints.
y = mx + b
where m = y / x & b = the y interrupt,
we can find values of y by incrementing x from
x =x1, to x = x2.
By scan-converting these calculated x, y values, we
represent the line as a sequence of pixels.
4
3/24/2024
Properties of Good Line Drawing
Algorithm
Line should appear Straight
Lines should terminate accurately
Lines should have constant density
Line density should be independent of line length and
angle
Line should be drawn rapidly
Algorithm for line Drawing
Direct use of line equation
DDA (Digital Differential Analyzer)
Bresenham's Algorithm
5
3/24/2024
1- Direct use of line equation
It is the simplest form of conversion. First of all scan
P1 and P2 points. P1 has co-ordinates (x1',y1') and (x2' y2'
).
Example: A line with starting point as (0, 0) and ending
point (6, 18) is given. Calculate value of intermediate
points and slope of line.
Solution: P1 (0,0) P7 (6,18)
x1=0
y1=0
x2=6
y2=18
We know equation of line is
y=mx+b
y = 3x + b......equation (1)
put value of x from initial point in equation (1), i.e.,
(0, 0) x = 0, y = 0
0=3x0+b
0 = b ⟹ b=0
put b = 0 in equation (1)
y = 3x + 0
y = 3x
6
3/24/2024
Intermediate points
Now calculate intermediate points
Let x = 1 ⟹ y = 3 x 1 ⟹ y = 3
Let x = 2 ⟹ y = 3 x 2 ⟹ y = 6
Let x = 3 ⟹ y = 3 x 3 ⟹ y = 9
Let x = 4 ⟹ y = 3 x 4 ⟹ y = 12
Let x = 5 ⟹ y = 3 x 5 ⟹ y = 15
Let x = 6 ⟹ y = 3 x 6 ⟹ y = 18
So points are P1 (0,0)
P2 (1,3)
P3 (2,6)
P4 (3,9)
P5 (4,12)
P6 (5,15)
P7 (6,18)
Algorithm for drawing line using
equation
Step1: Start Algorithm
Step2: Declare variables x1,x2,y1,y2,dx,dy,m,b,
Step3: Enter values of x1,x2,y1,y2.
The (x1,y1) are co-ordinates of a starting point of
the line.
The (x2,y2) are co-ordinates of a ending point of
the line.
Step4: Calculate dx = x2- x1
Step5: Calculate dy = y2-y1
Step6: Calculate m =
Step7: Calculate b = y1-m* x1
7
3/24/2024
Step8: Set (x, y) equal to starting point, i.e., lowest point
and xend equal to largest value of x.
If dx < 0
then x = x2
y = y2
xend= x1
If dx > 0
then x = x1
y = y1
xend= x2
Step9: Check whether the complete line has been drawn
if x=xend, stop
Step10: Plot a point at current (x, y) coordinates
Step11: Increment value of x, i.e., x = x+1
Step12: Compute next value of y from equation y = mx +
b
Step13: Go to Step9.