Академический Документы
Профессиональный Документы
Культура Документы
Computer graphics
Tablets
Touch panels
Joysticks
Trackball
Mouse
Light pen
Keyboard
Space ball
Vector and raster graphics
DAC
1 Electron gun
1
0
0 0 1
2^3 DAC
Electron gun
Raster CRT for RGB (8 colors)
1 1 DAC blue
0
0 DAC green
0 0 DAC red
Buffer color combinations
0 0 0 0 1 0 1 0
RED 10
2D Graphics Pipeline
Clipping
Object window to
Object Applying
subset viewport
World Coordinates world window
mapping
Object
Display Rasterization
Screen coordinates
Rasterization Operations
8
7 Line: (3,2) -> (9,6)
6
5
4
? Which intermediate
pixels to turn on?
3
2
1
0 1 2 3 4 5 6 7 8 9 10 11 12
Line drawing algorithms
(x1,y1)
dy
(x0,y0)
dx
DDA Line Drawing Algorithm
By Ay 96 41 55
m 0.5392
Bx Ax 125 23 102
Digital Differential Analyzer (DDA): Line Drawing
Algorithm
(x1,y1)
dy
(x0,y0)
dx
DDA Line Drawing Algorithm (Case a: m < = 1)
y k 1 y k m x = x0 y = y0
x=x+1 y=y+1*m
Until x == x1
(x0, y0)
DDA Line Drawing Algorithm (Case b: m > 1)
1 x = x0 y = y0
x k 1 xk (x1,y1)
m Illuminate pixel (round(x), y)
y = y0 + 1 x = x0 + 1 * 1/m
y=y+1 x = x + 1 /m
(x0,y0) Until y == y1
DDA Line Drawing Algorithm Pseudocode
compute m;
if m <= 1:
{
float y = y0; // initial value
//x0 is smallest value between xo and x1
for(int x = x0;x <= x1; x++, y += m)
setPixel(x, round(y));
}
else // m > 1
{
float x = x0; // initial value
//y0 is smallest value between yo and y1
for(int y = y0;y <= y1; y++, x += 1/m)
setPixel(round(x), y);
}
Note: setPixel(x, y) writes current color into pixel in column x and
row y in frame buffer
Line Drawing Algorithm Drawbacks
M=-4/-8=0.5 m<1
X0=-8 y0=-4
Find out intermediate pixels for line with end
points (4,2) & (6,7)
M=(7-2)/(6-4)=5/2 m>1
X0=4 y0=2
Find out intermediate pixels for line with end
points (2,-3) & (-3,3)
M=6/-5 m>1
X0=2 y0=-3