You are on page 1of 47

CS 325

Introduction to Computer Graphics

01 / 29 / 2014
Instructor: Michael Ecmann
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
#oda\$%s #opics
&
&
)resenham!*ine dra+in" al"orithm
&
Midpoint!circle dra+in" al"orithm
&
Ellipse dra+in"
&
,ntialiasin"
&
-ol\$"ons
&
-ol\$"on .illin" al"orithm
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
)resenham/s *ine ,l"orithm
&
)resenham/s ,l"orithm is e..icient 0.ast1 and accurate2
&
#he e\$ part o. )resenham/s al"orithm lies in the determination
o. +hich pi3el to turn on 4ased on +hether the line e5uation
+ould cause the line to lie more near one pi3el or the other2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
)resenham/s *ine ,l"orithm
&
#hin o. a line +hose slope is 607 4ut 8 12 #hese are .irst octant lines 0the
area o. the coordinate plane 4et+een the positi9e 3!a3is and the line \$:321
& ,ssume +e ha9e the pi3el at 03

7 \$

1 turned on and +e/re tr\$in" to determine

4et+een the .ollo+in":
; Should 03
<1
7 \$

1 or 03
<1
7 \$
<1
1 4e on(
; #hat is7 the choice is 4et+een either the pi3el one to the ri"ht o. 03

7 \$

1
or the pi3el one to the ri"ht and one up2
& #he decision can 4e made 4ased on +hether d
lo+er
! d
upper
is positi9e or not2
&
#he "oal is to come up +ith an ine3pensi9e +a\$ to determine the si"n o.
0d
lo+er
; d
upper
1
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
)resenham/s *ine ,l"orithm
& #he \$ coordinate on the line is calculated 4\$: \$ : m03

< 11 < 4 and

& d
lo+er
: \$ ; \$

& d
upper
: \$
<1
; \$
& d
lo+er
; d
upper
: 2m03

< 11 ; 2\$

< 24 ; 1
&
Since m is 8 1 0recall it/s in the 1
st
octant1 it is a non!inte"er2 #hat/s not "ood so7
replace it +ith d\$/d37 +here d\$ is the chan"e in \$ endpoints and d3 is the chan"e in
3 endpoints ; these +ill 4e inte"er 9alues di9ided !!! 4ut +e/ll "et rid o. the di9ision2
& d
lo+er
; d
upper
: 2 0 d\$ / d3 103

< 11 ; 2\$

< 24 ; 1
&
Multipl\$ 4oth sides 4\$ d3 and "et:
& d3 0d
lo+er
; d
upper
1 : 2 d\$ 03

< 11 ; 2 d3 \$

< 2 d3 4 ; d3
& d3 0d
lo+er
; d
upper
1 : 2 d\$ 3

; 2 d3 \$

< 2 d\$ < 2 d3 4 ; d3
&
2 d\$ < 2 d3 4 ; d3 is a constant +hich is independent o. each iteration
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
)resenham/s *ine ,l"orithm
&
So +e end up +ith
& d3 0d
lo+er
; d
upper
1 : 2 d\$ 3

; 2 d3 \$

< c
& =e onl\$ need to determine the si"n o. 0d
lo+er
; d
upper
1
&
d3 is positi9e so it doesn/t ha9e an e..ect on the si"n 0so no+ there/s no need to
di9ide1 !!! does that mae sense(
& *et p

: d3 0d
lo+er
; d
upper
1 p
k
is the decision parameter
& So7 +e chec i. 2 d\$ 3

; 2 d3 \$

03
<1
7 \$

1 should 4e the pi3el turned on

& other+ise 03
<1
7 \$
<1
1 is turned on
&
,s the al"orithm iterates thou"h it needs to then calculate the ne3t 9alue o. p7 +hich
is p
<1
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
)resenham/s *ine ,l"orithm
& >ecall that to calculate p

: 2 d\$ 3

; 2 d3 \$

< c
& So7 p
<1
: 2 d\$ 3
<1
; 2 d3 \$
<1
< c
& I. +e su4tract p
<1
; p

: 2d\$ 0 3
<1
; 3

1 ; 2d3 0 \$
<1
; \$

1
& )ut7 3
<1
: 3

& So7 +e ha9e p
<1
; p

: 2d\$ ; 2d3 0 \$
<1
; \$

1
& #hen7 p
<1
: p

< 2d\$ ; 2d3 0 \$
<1
; \$

1
& =here 0 \$
<1
; \$

1 is either 1 or 0 0+h\$(1 dependin" on the si"n o. p

2 So7 either
& p
<1
: p

< 2d\$ 0+hen p

8 01
& p
<1
: p

< 2d\$ ; 2d3 0+hen p

6: 01
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Initial decision 9aria4le 9alue
&
#he initial 9alue o. p in the )resenham line al"orithm
is calculated 4\$ usin" the e5uation .or p +ith 03
0
7 \$
0
1
&
?eri9ation:
p

: 2d\$3

; 2d3\$

< c
+here c : 2d\$ < d3024!11
and since \$

:m3

<47 4 : \$

;m3

and m : d\$/d3
p

: 2d\$3

; 2d3\$

; 0d\$/d313

1; 11
multiplied out:
p

: 2d\$3

; 2d3\$

< 2d\$ < 2d3\$

; 2d\$3

; d3
: 2d\$ ; d3
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
)resenham/s *ine ,l"orithm
/@ )resenham line!dra+in" procedure .or AmA 8 1202 @/
9oid line)res 0int 307 int \$07 int 3End7 int \$End1
B
int d3 : .a4s 03End ! 3017 d\$ : .a4s0\$End ! \$01C
int p : 2 @ d\$ ! d3C
int t+o?\$ : 2 @ d\$7 t+o?\$Minus?3 : 2 @ 0d\$ ! d31C
int 37 \$C
/@ ?etermine +hich endpoint to use as start position2 @/
i. 030 6 3End1 B
3 : 3EndC
\$ : \$EndC
3End : 30C
D
else B
3 : 30C
\$ : \$0C
D
set-i3el 037 \$1C
+hile 03 8 3End1 B
3<<C
i. 0p 8 01
p <: t+o?\$C
else B
\$<<C
p <: t+o?\$Minus?3C
D
set-i3el 037 \$1C
D
D
/@ Erom Fearn G )aer/s Computer Graphics +ith
HpenG*7 3
rd
Edition @/
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Circle ,l"orithms
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Circle ,l"orithms
&
So7 +e onl\$ need to calculate the coordinates o. an ei"hth o. the circle and plot the
.ollo+in":
&
0!37 !\$17 0!37 \$17 037 !\$17 037 \$17 0\$7 317 0\$7 !317 0!\$7 317 0!\$7 !31
&
)resenham/s *ine ,l"orithm has 4een adapted to circles 4\$ decidin" +hich pi3el is
closest to the actual circle at each samplin" step2
&
It should 4e a4le to dra+ circles +ith an\$ center7 4ut to mae calculations easier7
compute the pi3el coordinates 4ased on the same radius 4ut centered at the origin2
#hen +hen \$ou plot the pi3el7 add in the center coordinates2
&
Consider onl\$ the octant 4et+een the lines 3:0 and \$:32 #he slope o. the cur9e
9aries .rom 0 0at the top1 to !1 at the 45 de"ree an"le2 #his implies that +e should
do unit steps on the 3!a3is and calculate \$ 0I lea9e this .or \$ou to con9ince \$oursel.
that this is the ri"ht approach21
&
,t each 37 the decision is 4et+een +hich \$ is correct amon" t+o possi4le \$/s7 the
one to the ri"ht or the one to the ri"ht and do+n2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Circle ,l"orithms
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Circle ,l"orithms
&
#he decision is al+a\$s 4et+een the pi3el one to the ri"ht or one to the ri"ht and one
do+n2 >especti9el\$7 \$

or \$

!12
&
#he midpoint circle al"orithm is a +a\$ to determine it usin" onl\$ inte"er arithmetic2
&
?e.ine a circle .unction as .037\$1 : 3
2
< \$
2
; r
2

&
, point 37\$ on the circle +ith radius r +ill cause .037\$1 : 0
&
, point 37\$ in the circle/s interior +ill cause .037\$1 8 02
&
, point 37\$ outside the circle +ill cause .037\$1 6 02
&
#he point +e use is the midpoint 4et+een the t+o pi3el choices2 ,nd .037\$1 as
de.ined a4o9e is our decision 9aria4le p

< 17 \$

; I1
& I. p

& Hther+ise choose \$

!1
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Circle ,l"orithms
& p

: .03

< 17 \$

; I1 : 03

< 11
2
< 0\$

; I1
2
; r
2

& I. p

& Hther+ise choose \$

!1
& p
<1
: .03
<1
< 17 \$
<1
; I1 : 03
<1
< 11
2
< 0\$
<1
; I1
2
; r
2

& p
<1
: 003

< 11 < 11
2
< 0\$
<1
; I1
2
; r
2
0p
<1
can 4e e3pressed in terms o. p

1

&
Similar to ho+ +e determined the recursi9e decision 9aria4le computation in )resenham/s
*ine ,l"orithm7 +e do .or the Circle ,l"orithm as +ell: sippin" a 4unch o. steps leads to:
& p
<1
: p

< 23
<1
< 1 0+hen p

8 01
& p
<1
: p

< 23
<1
< 1 ; 2\$
<1
0other+ise1
& ,ssumin" +e start at point 007r17 +e/ll ha9e p
0
: .00 < 17 r ; I1 : .017 r ; I1 +hich \$ields
5/4 ; r 0or 1; r .or inte"er radii 4ecause o. roundin"1
&
*et/s plot some points as an e3ample .or a circle o. radius J7 and center 0!27 41
&
=e do calculations +ith center 070 and .or each point +e plot7 +e add in the center2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Circle ,l"orithm E3ample
Center = (-2, 4)
K
0 -5 (1, 6) (-1, 10) 2 12
1 -2 (2, 6) (0, 10) 4 12
2 3 (3, 5) (1, 9) 6 10
P
k
(x
k+1
, y
k+1
) Center + (x
k+1
, y
k+1
) 2x
k+1
2y
k+1
& p
0
: 1; r
& p
<1
: p

< 23
<1
< 1 0+hen p

8 01
& p
<1
: p

< 23
<1
< 1 ; 2\$
<1
0other+ise1
&
-lot: 0!17 1017 007 1017 017 917 027 K1
&
,lso7 plot points in the other L octants .or each o. these .our2
&
e2"2 #he other L points .or 0!17 101 to plot are:
&0!37 1017 0!17!217 0!37!217 047517 047 317 0!K7 517 0!K7 31
&#hese +ere calculated 4\$ addin" the center 0!2741 to 0!17J17 017!J17 0!17!J17 0J7 117
0J7!117 0!J7117 and 0!J7!11
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Circle ,l"orithms
&
#here/s a .i"ure in the te3t 4oo 0.i"ure J!151 and it loos to me lie the circle line is
dra+n incorrectl\$ 4ut the pi3els are correct2 It is sho+in" the center o. the circle at
the 4ottom le.t corner o. the 070 pi3el 4o37 4ut it should 4e in the center o. the 070
pi3el 4o32
&
I noticed it 4ecause +hen 3:37 4ased on the dra+n circle7 the al"orithm +ould Mturn
onN 03791 not 0371017 4ecause the midpoint is clearl\$ outside the circle there2
& I didn/t 9eri.\$ it7 4ut I trust the calculations in the ta4le +hich sa\$s that p
2
: !1 +hich
+ould 4e inside the circle2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Ellipse ,l"orithm
&
=e can "eneraliOe the circle al"orithm to "enerate ellipses 4ut
+ith onl\$ 4!+a\$ s\$mmetr\$2
&
#he slope o. the ellipse chan"es .rom 6 !1 to 8 !1 in one
5uadrant so that +e +ill ha9e to s+itch .rom
;
unit samples alon" the 3!a3is and calculate \$
;
to unit samples alon" the \$!a3is and calculate 3
&
I/m not as concerned a4out the details o. ellipses as I am +ith
\$ou understandin" the details o. the line and circle al"orithms2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Ellipse ,l"orithms
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
Ellipse ,l"orithms
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin"
&
,liasin" is the distortion +e see +hen +e undersample2 #he
Pa""edness stairstep 5ualit\$ o. lines is an e3ample o. aliasin"2
&
Solutions:
;
&
e2"2 Mo9e .rom a K003J00 "rid to a 12K031024 "rid and
\$our lines +ill loo smoother2
&
I. eep addressa4ilit\$ .i3ed then +e can chan"e the
intensit\$ o. the pi3els 4ein" turned on2 Instead o. turnin"
on one pi3el at .ull intensit\$7 +e appropriatel\$ +ei"ht the
intensities o. t+o pi3els at each step to cause the illusion o.
a point li9in" at some intermediate location 4et+een the
t+o pi3el centers2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin"
&
E3ample on the 4oard2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin"
&
,n\$ ideas on ho+ +e could adapt )resenham/s line al"orithm to
do antialiased lines(
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin"
&
,n\$ ideas on ho+ +e could adapt )resenham/s line al"orithm to
do antialiased lines(
& d
lo+er
< d
upper
: 1
&
#he upper pi3el/s intensit\$
can 4e set to 4e d
lo+er
&
#he lo+er pi3el/s intensit\$
can 4e set to 4e d
upper
&
=hen the line passes e3actl\$ throu"h the center o. a pi3el7 that
pi3el/s intensit\$ is 1 and the other is 0 0o..12
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin"
&
Supersampling is a techni5ue to treat the screen as a .iner "rid than is
actuall\$ addressa4le and plot the points 4\$ turnin" on multiple points in
the .iner "rid2 #hen +hen read\$ to displa\$ !!! use the .iner "rid points to
determine the intensities o. the pi3els o. the actual screen2
&
E3ample !!! di9ide each actual addressa4le pi3el into 9 03331 .iner
su4pi3els2 ?ra+ a )resenham line on the su4pi3els2 #hen 4ase the
intensit\$ o. actual pi3el on ho+ man\$ o. the 9 su4pi3els +ould 4e on2
;
3 su4pi3els is ma37 so that/s .ull intensit\$
;
2 su4pi3els could cause the pi3el to 4e at 2/3 intensit\$
;
1 su4pi3el on could cause the pi3el to 4e at 1/3 intensit\$
;
0 +ould 4e o..
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin"
&
,lternatel\$7 +e could use a +ei"htin" mas that +ould "i9e more
+ei"ht to the center su4pi3el o. the 333 "rid
1 2 1
2 4 2
1 2 1
&
,nother alternati9e is to treat the line as a rectan"le o. +idth 1
pi3el G dra+ it on the .iner "rid 0+/ 9 su4pi3els per pi3el12 #hen
ho+ man\$ o. the 9 su4pi3els are on 0on : 4ottom le.t corner o.
su4pi3el is inside the rectan"le1 determines the intensit\$ o. pi3el
09 : .ull intensit\$7 K : K/9 intensit\$7 etc21 #his is 4etter than the
three intensit\$ le9els o. the other supersamplin" method2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin"
&
Area sampling is a techni5ue that computes areas o. o9erlap o.
each pi3el +ith the o4Pect 0e2"2 line or pol\$"on1 to 4e displa\$ed2
&
#his is similar to the supersamplin" method descri4ed last
0treatin" the line as a rectan"le17 4ut instead o. Pust 9 di..erent
intensities7 let the intensit\$ o. a pi3el 4e the area o. the rectan"le
that o9erlaps the pi3el / the area o. the +hole pi3el2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin"
&
#here are other techni5ues to do antialiasin" !!! .ilterin"
techni5ues2 #hese are similar to the discrete mas t+o slides a"o7
e3cept the\$ +or +ith a continuous .unction to determine the
+ei"htin"s o. the pi3els2 E3amples on the ne3t slide sho+ a 4o37 a
cone and a "aussian2 #he 9olumes o. these are normaliOed to 1
and to determine the +ei"htin" o. a pi3el +e inte"rate the .unction
o9er the pi3el sur.ace2 Since inte"ratin" is e3pensi9e 0in time1
looup ta4les can 4e used2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin"
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin" also helps +ith 222
&
Qotice: +ithout antialiasin"7 compare a line +ith slope : 1 made
up o. n pi3els and a line +ith slope : 0 made up o. n pi3els2
&
#he slope : 1 line is S'>#021 lon"er 4ut is made up o. the same
num4er o. pi3els2 =hat do \$ou thin is the 9isual e..ect o. this(
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
,ntialiasin" helps total intensit\$
&
See .i"ures J!J3 G J!J4 in te3t2
&
In addition to lines looin" strai"hter7 +hen usin" the antialiasin"
techni5ue that treats lines as ha9in" some .inite +idth7 lines o.
di..erent an"les +ill not ha9e di..erent total intensities2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"ons
&
3 or more vertices descri4e a polygon2 #he 9ertices are
connected +ith line se"ments 0called an edge7 or a side12 Each
ed"e can onl\$ ha9e endpoints in common +ith an\$ other ed"e2
&
?e.inition o. convex pol\$"on
;
?e. 1: ,ll interior an"les are 8 1K0 de"rees
;
?e. 2: #he interior lies completel\$ on 1 side o. the in.inite
e3tension o. an\$ ed"e2
;
?e. 3: I. +e select an\$ t+o interior points7 the line se"ment
Poinin" them is also .ull\$ in the interior o. the pol\$"on
&
?e.inition o. concave pol\$"on
;
Qot con9e32
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"ons
&
?e"enerate pol\$"ons are
;
#hose +ith 3 or more collinear 9ertices
;
#hose +ith repeated 9ertices
;
Etc2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on interior points
&
, common operation is to determine i. a point is in the interior o.
a pol\$"on or not2
&
Hne +a\$ to do it is7 .or some point7 dra+ a horiOontal line .rom
that point to a distant point outside the possi4le area o. the
pol\$"on and count ho+ man\$ times the horiOontal line crosses
ed"es o. the pol\$"on2
&
I. the line crosses an odd num4er o. ed"es7 then it is an interior
point2 I. it crosses an e9en num4er o. ed"es7 then it is e3terior2
&
E3ample on 4oard2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on interior points
&
=hat happens +hen the horiOontal line crosses a 9erte32 Should it
4e counted as 1 or 2(
&
E3ample on 4oard2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on interior points
&
=hat happens +hen the horiOontal line crosses a 9erte32 Should it
4e counted as 1 or 2(
&
I. the 9erte3 is a local ma3imum or a local minimum then count it
as 22 Hther+ise count it as 12
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
-ol\$"ons in HpenG* are speci.ied 4\$ 9ertices2 It is "ood to "et
into the ha4it no+ that \$ou speci.\$ the 9ertices in
countercloc+ise order2
&
#he reason .or this is7 +hen +e do some thin"s later this semester
lie displa\$in" 3? o4Pects7 +e/re "oin" to care a4out +hich side
0.ace1 o. the pol\$"on is 9isi4le2
&
#he .ront .ace o. a pol\$"on is 9isi4le +hen its 9ertices are in
countercloc+ise order2 =e/ll no+ i. +e/re seein" the 4ac .ace
o. a pol\$"on i. the\$ are in cloc+ise order2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
#o do a scanline .ill o. a pol\$"on 0see .i"ure J!4J7 4L7 4K12
;
?etermine the intersections 0crossin"s1 o. the horiOontal line
0\$:c1 +ith the ed"es 0\$:m3 < 41 o. the pol\$"on2
;
Sort the crossin"s 03 coordinates1 .rom lo+ to hi"h 0le.t to
ri"ht12
;
#here +ill 4e an e9en num4er o. crossin"s7 so dra+ horiOontal
lines 4et+een the .irst t+o crossin"s7 then the ne3t 2 and so on2
;
I. the scanline "oes throu"h a 9erte3
&
,dd the crossin" to the list t+ice i. it/s a local ma3 or min2
&
,dd the crossin" onl\$ once other+ise2
&
ForiOontal ed"es o. a pol\$"on can 4e i"nored 0not turned on21
&
E3ample on 4oard2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
,nother +a\$ to determine ho+ man\$ to count i. the scanline "oes
throu"h a 9erte3
&
I. the t+o ed"es are on the same side o. the scanline7 then
&
I. the t+o ed"es are on di..erent sides o. the scanline7 then
&
#o chec .or this7 +e can compare the \$ coordinates o. the 3
9ertices in 5uestion 0dra+ on 4oard1 in either cloc+ise or
countercloc+ise .ashion
;
I. all 3 are monotonicall\$ increasin" or all 3 are monotonicall\$
decreasin" then the t+o ed"es are on di..erent sides2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
Ed"e coherence properties can 4e used to speed up the calculation o. the
crossin"s o. the scanline and ed"es2 #he crossin" 3!coordinate o. one
scanline +ith an ed"e di..ers .rom the crossin" o. the 3!coordinate o. the
ne3t scanline onl\$ 4\$ 1/m as seen 4elo+2
&
,ssumin" +e/re processin" the .ill .rom 4ottom to top and the \$/s
increase as +e "o up7
; ,ssume scan line \$

crosses an ed"e at 03

7 \$

1 and \$
<1
crosses at
03
<1
7 \$
<1
1
; m : 0\$
<1
; \$

1 / 03
<1
; 3

1
; 0\$
<1
; \$

1 : 17 so7 m : 1 / 03
<1
; 3

1 and sol9e .or 3
<1
; So7 scan line \$
<1
crosses that ed"e at 03

< 1/m7 \$
<1
1
& #his is less processin" than doin" the intersection o. \$ : \$
<1
+ith
\$ : m3 < 4 +hich is 3 : 0\$
<1
<41/m2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
E..icient pol\$"on .illin"
;
11 proceed around ed"es in a cloc+ise or countercloc+ise .ashion
;
21 store each ed"e in an ed"e ta4le
;
31 sort the ed"es 4ased on the minimum \$ in the ed"e
;
41 process the scanlines in a 4ottom to top order
;
51 +hen the current scanline reaches the lo+er endpoint 0+ith the
min \$1 o. the ed"e7 that ed"e 4ecomes acti9e
;
J1 acti9e ed"es are sorted 4\$ their 3 coordinates 0le.t to ri"ht1
;
?urin" an\$ "i9en scanline non!acti9e ed"es can 4e mared as either
.inished7 or not \$et acti9e2 ForiOontal ed"es are i"nored2
&
E3ample on 4oard2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
Mass
;
)esides 4ein" .illed +ith a solid color7 pol\$"ons are
sometimes .illed +ith patterns2 #he process o. .illin" an
area +ith a pattern is called tiling2
;
Eill patterns can 4e stored as rectan"ular arra\$s2 #he
arra\$s are called masks and the\$ are applied to the .ill
area and are usuall\$ smaller than the area to 4e .illed2
;
#he mas needs a startin" position +ithin the area to 4e
.illed2 Startin" at this position the mas is replicated 4oth
9erticall\$ and horiOontall\$2
;
I. the mas is an m n arra\$7 and startin" position is 00701
a pi3el at 037 \$1 +ill 4e dra+n +ith the color in mas003
mod n17 0\$ mod m112
;
E3ample on 4oard2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
Section 1L29 Fal.tonin" and ditherin"
;
=hen there are 9er\$ .e+ intensit\$ le9els a9aila4le 0e2"2 27
4lac G +hite1 to 4e displa\$ed7 halftoning is a techni5ue
that can pro9ide more intensities +ith the tradeo.. in
;
Qe+spapers sho+ "re\$ le9el photos 4\$ displa\$in" 4lac
circles2 #he 4lac circles 9ar\$ in siOe accordin" to ho+
dar that part o. the photo should 4e2
;
In "raphics s\$stems this hal.tonin" techni5ue is
appro3imated +ith hal.tone patterns2 Fal.tone patterns are
t\$picall\$ n n s5uares o. pi3els +here the num4er o.
pi3els turned on in that pattern correspond to the intensit\$
desired2
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
0resolution1 (
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
Guidelines to creatin" hal.tonin" patterns
;
=ith hal.tonin"7 one thin" to 4e care.ul a4out is that
unintended patterns can 4ecome apparent2 #he intent is to
ha9e the 9ie+er see the increase in intensities +ithout
noticin" unintentional patterns2
;
,9oid onl\$ horiOontal or 9ertical or dia"onal pi3els on in
the patterns to reduce the possi4ilit\$ o. MstreasN2
;
Eurther it is "ood to appro3imate the +a\$ that ne+spapers
do it !!! that is7 concentrate on turnin" on pi3els in the
center o. the pattern at each successi9e intensit\$2
;
#o minimiOe unintentional patterns to 4e displa\$ed7 +e
can e9ol9e each successi9e "rid pattern 4\$ cop\$in" it and
&
See ne3t slide .i"ure 10!402
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
&
?itherin"
;
?itherin" re.ers to techni5ues .or appro3imatin" hal.tones 4ut
;
,n nn dither matri3 ?
n
is used to detemine i. a pi3el should
4e on or o..2
;
#he matri3 is .illed +ith the num4ers .rom 0 to n
2
; 1
;
on pa"e 534 0e5uation 1L!491 there/s a mistae7 it should 4e the
dither matri3 ?
4
15 L 13 5
3 11 1 9
12 4 14 J
0 K 2 10
Michael Ecmann ! Sidmore
Colle"e ! CS 325 ! Sprin" 2014
-ol\$"on .ill areas
& E3ample o. dither matri3 ?
4
15 L 13 5
3 11 1 9
12 4 14 J
0 K 2 10
;
Eor some pi3el 037 \$1 an intensit\$ le9el I037\$1 4et+een 0 and n
2
is
desired2 Compute i : 3 mod n and P : \$ mod n to .ind +hich
element 0i7P1 o. the matri3 ?
n
to compare to the desired intensit\$2
; I. I037\$1 6 ?
n
0i7P1 then the pi3el is turned on7 other+ise it is not2
;
#his has the e..ect o. di..erent intensities7 +ithout reducin"
resolution2 )ut +hat "ets lost(