Professional Documents
Culture Documents
output primitives
.
2 UNIT I: Output Primitives
of
32
• Picture element.
• Smallest Addressable Screen element.
• Each pixel has a Name or Address.
• Computer Graphics images are made by
setting the intensity and colour of the pixels
composing the screen.
• Display Screen is a Grid or Array of pixels.
• The coordinate (i, j) will give the Col. and Row of a Pixel.
• Each pixel will be centred at its Coordinates.
(7, 5)
(2, 2)
x
8
of
32
The Problem (cont…)
But what happens when we try to draw this
on a pixel based display?
Slope-intercept line
yend equation:
y m x b
y0 where:
yend y0
m
x0 xend
x xend x0
b y0 m x0
11
of
32
7 7
6 6
5 5
4 4
3 3
2 2
1 1
0 0
13
of
32
Increment of x or y depends on slope
Sharp Slope Case:
If m>1, increm ent y and find x
dy can be set propos ional to a small vertical deflection
voltage and the corresponding horizontal deflection
voltage set propos ional to dx as calculated from eqn.
m = -1 m=1
m = -1/2 m = 1/ 2
m = -1 / 3 m = 1/ 3
m=0 m=0
15
of
32
A Very Simple Solution
We could simply work out the corresponding
y coordinate for each unit x coordinate
Let’s consider the following example:
y
(7, 5)
5
2
(2, 2)
x
2 7
16
of
32
A Very Simple Solution (cont…)
y
(7, 5) LINE EQUATION : y= mx+b
5
First work out m and b:
52 3
m
2
72 5
(2, 2)
3 4
b 2 2
2 3 4 5 6 7
x 5 5
Now for each x value work out the y value:
3 4 1
3 4
y (3) 3 2
3 y (4) 4 3
5 5 5 5 5 5
3 4 4 3 4 2
y (5) 5 3 y (6) 6 4
5 5 5 5 5 5
17
of
32
A Very Simple Solution (cont…)
Now just round off the results and turn on
these pixels to draw our line
3
7 y (3) 2 3
6 5
5 1
4
y ( 4) 3 3
5
3
4
2 y (5) 3 4
1 5
2
0
y (6) 4 4
0 1 2 3 4 5 6 7 8 5
18
of
32
A Very Simple Solution (cont…)
However, this approach is just way too slow
In particular look out for:
– The equation y = mx + b requires the
multiplication of m by x
– Rounding off the resulting y coordinates
We need a faster solution
23
of
32
The DDA Algorithm
The digital differential
analyzer (DDA) algorithm
takes an incremental
approach in order to
speed up scan conversion
Th e o r i g i n a l d i ffe r e n t i a l
Simply calculate yk+1 a na ly zer was a phys ica l
machine developed by
based on yk Vannevar Bush at MIT in the
1 93 0 ’s i n or der t o sol ve
ordinary differential equations.
24
of
Calculating the Values of ‘x’ and ‘y’
32
Step 1: For lines whose slope is positive and is less than or equal to 1
(m≤1)
These lines can be sampled at ‘x’ intervals i.e., x = 1 and the
corresponding ‘y’ values can be calculated using,
Yk+1 = Yk+ m
Where, ‘k’ takes the integer values starting from 1 and its value is
successfully incremented, till the last point is reached and the slope ‘m’
can either ‘0’ or’1’.
Step 2: For lines whose slope is positive and is greater than 1 (m>1)
These lines can be sampled at unit ‘y’ intervals i.e., y = 1 and the
corresponding ‘x’ values can be determined as,
xk+1 = xk / m
Line processing starts from left to right. If the first end point is at right then.
yk+1 = yk - m and xk+1 = xk / m
25
of
32
DDA algorithm
Step 1: Read the 2 end points (x1,y1), (x2,y2)
Step 2: Horizontal and vertical differences between the end points positions are
assigned to parameters dx and dy.
dx=x2-x1
dy=y2-y1
Step 3: The difference with the greater magnitude determines the value of parameter steps
If (abs(dx)> abs(dy)) then
steps = abs(dx) // Slant slope case
Else
steps = abs(dy) // Sharp slope case
Step 4: Starting with pixel positions (x1,y1) and we determine the offset needed at each
step to generate the next pixel position along the line path.
Xincrement = dx/ steps
Yincrement = dy/ steps
Step 5: Assign the values of x1, y1 to x,y respectively
x=x1 y=y1
Step 6: Plot the point at (x,y) positions on screen set pixel (round(x),round(y),1). Here 1 is
the intensity of pixel i.e, intensity with which picture illuminated.
Step 7: Calculate the values of x and y for next pixel position
X= x+Xincrement
Y= y+ Yincrement
Step 8: Plot the pixel at (x,y) position, set pixel(round(x),round(y),1).
Step 9: repeat the steps 7 and 8 until steps=0.
26 DDA Algorithm
of
32
29
of
32
DDA Example
Suppose we want to numsteps = 12 – 2 = 10
xinc = 10/10 = 1.0
draw a line starting at yinc = 5/10 = 0.5
pixel (2,3) and ending at t x y R(x) R(y)
pixel (12,8). 0 2 3 2 3
(7, 5)
5
2 2
(2, 2) (3, 2)
x x
2 7 2 3
31
of
32
DDA Algorithm Example (cont…)
0 1 2 3 4 5 6 7
32
of
32
Advantages of DDA
It calculates the pixel positions faster than
the calculations performed by using the
equation y=mx +b.