Professional Documents
Culture Documents
Output Primitives
Output Primitives
Output Primitives
of
39
Output Primitives
• DDA Line Drawing Algorithm
• Bresenham’s Line Drawing Algorithm
• Midpoint Algorithm for Circle
• Midpoint Algorithm for Ellipse
• Scan line Polygon Fill Method
• Boundary Fill Algorithm
• Flood Fill Algorithm
2
of
39
Pixel
Pixel or Pel is one of the many tiny dots that make
up the representation of a picture in a computer’s
memory.
- pix (picture)
- el (element)
Pixel is a smallest controllable element of a picture
represented on a screen
• m represents slope
• c represents Y-intercept
y2 y1 y mx
m
x2 x1 y
x
c y1 mx1 m
5
of
39
DDA Line drawing method
6
of
39
DDA Line drawing method
• Consider a line with positive slope <=1
y mx
y
x
m
• LE as SP RE as SP
xi 1 xi 1 xi 1 xi 1
yi 1 yi m yi 1 yi m
7
of
39
DDA Line drawing method
• Consider a line with positive slope > 1
y mx
y
x
m
• LE as SP RE as SP
xi 1 xi (1 m) xi 1 xi (1 m)
yi 1 yi 1 yi 1 yi 1
8
of
39
DDA Line drawing method
• Consider a line with negative slope |m|<=1
y mx
y
x
m
• LE as SP RE as SP
xi 1 xi 1 xi 1 xi 1
yi 1 yi m yi 1 yi m
9
of
39
DDA Line drawing method
• Consider a line with negative slope |m| > 1
y mx
y
x
m
• LE as SP RE as SP
xi 1 xi (1 m) xi 1 xi (1 m)
yi 1 yi 1 yi 1 yi 1
10
of
39
DDA Line drawing method
Line
Positive slope line Negative slope line
Left endpoint as Right endpoint as Left endpoint as Right endpoint as
starting point starting point starting point starting point
m≤1 m>1 m≤1 m>1 |m|≤1 |m|>1 |m|≤1 |m|>1
xi+1= xi+1= xi+1= xi+1= xi+1= xi+1= xi+1= xi+1=
xi+1 xi+1/m xi -1 xi-1/m xi+1 xi+1/m xi -1 xi-1/m
yi+1= yi+1= yi+1= yi+1= yi+1= yi+1= yi+1= yi+1=
yi+m yi+1 yi-m yi-1 yi-m yi-1 yi+m yi+1
11
of
39
DDA Line drawing method
1. Input the end points of a line (x1,y1) and
(x2,y2)
2. Plot the first point (x1,y1)
3. If | x2 - x1| >= | y2 - y1| then
length = | x2 - x1| else
length = | y2 - y1|
4. Calculate dx and dy as
dx = (x2 - x1)/length
dy = (y2 - y1)/length
12
of
39
DDA Line drawing method
5. From i = 1, increment by 1 each time
xi+1 = xi + dx
yi+1 = yi +dy
Plot(round(xi+1) , round(yi+1))
5. Repeat step 5 for length times
13
of
39
DDA Line drawing method
• The DDA algorithm is a better method for
calculating pixel positions than the use of
slope intercept form of equation.
• DDA eliminates the multiplication by
making use of raster characteristics , so
that appropriate increments are applied in
the x or y direction to step to pixel
positions along the line path.
14
of
39
DDA Line drawing method
• The accumulation of round of error in
successive additions of the floating point
increment can cause the calculated pixel
positions to drift away from the true line
path for long line segments.
• DDA is orientation dependent. Hence, end
point accuracy is sometimes not attained
• The rounding operations and floating point
arithmetic in DDA procedure are time
consuming.