Lecture2 E
Lecture2 E
In Region 1 dx > dy
(-x2,-y2) (x2,-y2)
Increase x at each step
(-x1,-y1) (x1,-y1)
y may decrease
In Region 2 dx < dy E
Tangent
Decrease y at each step Slope = -1 Gradient
x may increase SE Vector
At region boundary: Region 1
Region 2 S SE
dy
2 x b2 2 y a2 0
dx dy
In Region 1 1
dy b2 x dx
2
dx a y b2 x a 2 y
Midpoint Ellipse Algorithm
In region 1
d F ( x p 1, y p 12 )
( x p 1, y p 12 ) ( x p 2, y p 12 )
b ( x p 1) a ( y p ) a b
2 2 2 1 2
2
2 2
P=(xp, yp) E
if d 0 then move to E ME
yp
M
d new F ( x p 1, y p ) SE
MSE
yp – 1
b 2 ( x p 1) 2 a 2 ( y p ) 2 a 2b 2 yp – 2
xp xp+1 xp+2
if d 0 then move to SE ( x p 2, y p 32 )
Previous
Current
Next
d new F ( x p 1, y p 1)
b 2 ( x p 1) 2 a 2 ( y p 1) 2 a 2b 2
Midpoint Ellipse Algorithm
In region 2
Previous
Current
d F ( x p 12 , y p 1)
Next
b 2 ( x p 12 ) 2 a 2 ( y p 1) 2 a 2b 2 xp xp+1 xp+2
P=(xp, yp)
if d 0 then move to S yp
d new F ( x p , y p 1) S SE
yp – 1
M
b 2 ( x p ) 2 a 2 ( y p 1) 2 a 2b 2 MS MSE
yp – 2
( x p , y p 1)
1
2
if d 0 then move to SE
( x p 12 , y p 2) ( x p 2 , y p 2)
3
d new F ( x p 1, y p 1)
b 2 ( x p 1) 2 a 2 ( y p 1) 2 a 2b 2
Filling Polygons
So we can figure out how to draw lines,
circles and ellipse
How do we go about drawing polygons?
We use an incremental algorithm known as
the scan-line algorithm
Scan-Line Polygon Fill Algorithm
10 Scan Line
0
2 4 6 8 10 12 14 16
Scan-Line Polygon Fill Algorithm
The basic scan-line algorithm is as follows:
Find the intersections of the scan line with all
edges of the polygon
Sort the intersections by increasing x
coordinate
Fill in all pixels between pairs of intersections
that lie interior to the polygon
Scan-Line Polygon Fill Algorithm (cont…)