Computer Graphics 5: Line Drawing Algorithms: Course Website
Computer Graphics 5: Line Drawing Algorithms: Course Website
2
of
32
Contents
Graphics hardware
The problem of scan conversion
Considerations
Line equations
Scan converting algorithms
A very simple solution
The DDA algorithm
Conclusion
Images taken from Hearn & Baker, Computer Graphics with OpenGL (2004)
3
of
32
Graphics Hardware
Its worth taking a little look at how graphics
hardware works before we go any further
How do things end up on the screen?
4
of
32
Display
Processor
Memory
CPU
Display
Processor
System Bus
Frame
Buffer
System
Memory
Video
Controller
Monitor
5
of
32
Output Devices
There are a range of output devices
currently available:
Printers/plotters
Cathode ray tube displays
Plasma displays
LCD displays
3 dimensional viewers
Virtual/augmented reality headsets
Images taken from Hearn & Baker, Computer Graphics with OpenGL (2004)
6
of
32
Images taken from Hearn & Baker, Computer Graphics with OpenGL (2004)
7
of
32
Images taken from Hearn & Baker, Computer Graphics with OpenGL (2004)
8
of
32
Colour CRT
Images taken from Hearn & Baker, Computer Graphics with OpenGL (2004)
9
of
32
Plasma-Panel Displays
Applying voltages to
crossing pairs of
conductors causes
the gas (usually a
mixture including
neon) to break
down into a glowing
plasma of electrons
and ions
Images taken from Hearn & Baker, Computer Graphics with OpenGL (2004)
10
of
32
11
of
32
(7, 5)
(2, 2)
x
12
of
32
13
of
32
Considerations
Considerations to keep in mind:
The line has to look good
Avoid jaggies
14
of
32
Line Equations
Lets quickly review the equations involved
in drawing lines
Slope-intercept line
y
equation:
y m x b
yend
where:
yend y0
m
xend x0
y0
x0
xend
b y0 m x0
15
of
32
m=
m=4
m=2
m=1
m = 1/2
m = -1/3
m = 1/3
m=0
m=0
16
of
32
(2, 2)
2
17
of
32
18
of
32
y
5
52 3
m
72 5
2
(2, 2)
3
4
b 2 2
x
5
5
2 3 4 5 6 7
Now for each x value work out the y value:
3
4
3
y (3) 3 2
5
5
5
3
4
4
y (5) 5 3
5
5
5
3
4
1
y (4) 4 3
5
5
5
3
4
2
y (6) 6 4
5
5
5
19
of
32
3
y (3) 2 3
5
1
y (4) 3 3
5
4
y (5) 3 4
5
2
y (6) 4 4
5
20
of
32
21
of
32
yend y0
where: m
and b y0 m x0
xend x0
22
of
32
1
x(4) 5 5
3
7
6
5
4
3
2
1
0
0
23
of
32
m=
m=4
m=2
m=1
m = 1/2
m = 1/3
m=0
24
of
32
25
of
32
26
of
32
27
of
32
yk 1 yk m
When the slope is outside these limits,
increment the y coordinate by 1 and calculate
the corresponding x coordinates as follows:
1
xk 1 xk
m
28
of
32
(xk+1, round(yk+m))
(xk, yk)
(xk+1, yk+m)
(xk, round(yk))
29
of
32
(2, 7)
(7, 5)
(2, 2)
2
(3, 2)
30
of
32
31
of
32
32
of
32
Conclusion
In this lecture we took a very brief look at
how graphics hardware works
Drawing lines to pixel based displays is time
consuming so we need good ways to do it
The DDA algorithm is pretty good but we
can do better
Next time well like at the Bresenham line
algorithm and how to draw circles, fill
polygons and anti-aliasing