Vous êtes sur la page 1sur 24

!

"#$ &'$()*+,'$
1
Lecture-4
LecLure CuLllne
Scan Converslon (?)
olnL
Llne
Clrcle
! llnal sLep of rasLerlsauon (process of Laklng geomeLrlc
shapes and converung Lhem lnLo an array of plxels sLored
ln Lhe frame-buer Lo be dlsplayed)
! All graphlcs packages do Lhls aL Lhe end of Lhe renderlng
plpellne
! Also Lakes lnLo accounL oLher properues llke llghung and
shadlng
WhaL ls Scan Converslon?
olnL Scan
olnL ploLLlng ls furnlshed by converLlng a slngle
coordlnaLe poslLlon lnLo approprlaLe operauons for
Lhe ouLpuL devlce ln use.
8andom scan uses sLored polnL-ploLung lnsLrucLlons
(coordlnaLes) and converL Lhem ln deecLlon volLage
LhaL poslLlons Lhe elecLron beam aL Lhe screen
locauons Lo be ploLLed durlng each refresh cycle.
olnL Scan.1
8asLer scan depends on seLLlng Lhe blL value
correspondlng Lhe speclfled screen posluon wlLhln
Lhe frame buffer Lo 1. 1he elecLron beam when
sweeps across such posluon ln a llne emlLs bursL of
elecLrons wlLh lnLenslues correspondlng Lo colour
codes Lo be dlsplayed aL LhaL locauon.
olnL Scan.2
LeL, scan-converL a polnL (x, y) Lo a plxel locaLlon (x', y')
x' = lloor(x), and y' = lloor(y)
Where lloor ls a funcuon LhaL reLurns largesL lnLeger LhaL ls
less Lhan or equal Lo Lhe argumenL.
ln such a case, Lhe orlgln ls placed aL Lhe lowesL le
corner of Lhe plxel grld ln Lhe lmage space
All polnLs LhaL sausfy x' ! x < x'+1 and y' ! y < y' + 1 wlll
be mapped Lo plxel locauon (x', y') (refer llg a)
LeL us Lake for example a polnL 1 (1.7, 0.8). lL wlll be represenLed by plxel (1, 0). olnLs 2 (2.2, 1.3) and 3(2.8, 1.9)
are boLh represenLed by plxel (2, 1).
olnL Scan.3
olnL Scan.4
lf Lhe orlgln of coordlnaLe sysLem for (x, y) ls Lo
be shlfLed Lo new locaLlon say (x+0.3, y+0.3),
Lhen
x' = lloor(x+0.3), and y' = lloor(y+0.3)
1hls wlll place Lhe orlgln of Lhe coordlnaLe sysLem
(x, y) aL Lhe cenLre of plxel (0, 0)
now, all polnLs LhaL saLlsfy x'-0.3 ! x < x'+0.3 and
y'-0.3 ! y < y'+0.3 wlll be mapped Lo plxel locauon
(x', y') (refer llg b)
1hls means LhaL polnLs 1 and 2 are now boLh represenLed by plxel (2, 1), whereas polnL 3 ls represenLed by plxel (3, 2).
Llne Scan-Converslon
Llne ploLung ls done by calculaung lnLermedlaLe
posluons beLween Lhe Lwo specled endpolnL posluons.
Llnearly varylng horlzonLal and verucal deecuon
volLages are generaLed ln proporuon Lo Lhe requlred
changes ln x, y dlrecuons Lo produce Lhe smooLh llne.
A sLralghL llne segmenL ls dlsplayed by ploLung Lhe
dlscreLe polnLs beLween endpolnL posluons.
1hese lnLermedlaLe poslLlons are calculaLed from Lhe equauon
of Lhe llne
Colour lnLenslLy ls loaded lnLo Lhe frame buffer aL Lhe
correspondlng plxel coordlnaLe
Llne Scan-Converslon.1
Screen locauons are referenced wlLh lnLeger values. L.g.
(10.48, 20.31) wlll be converLed Lo plxel posluon (10, 20)
1hls roundlng effecL causes llnes Lo be dlsplayed wlLh a
sLalrsLep appearance . 1hls ls nouceable on low resoluuon
sysLems.
8eLLer smooLhlng can be achleved by ad[usung llghL
lnLenslues along Lhe llne paLhs.
Llne Scan-Converslon.2
lxel column number ls baslcally plxel posluon across a
scan llne. 1hese are lncreaslng from le Lo rlghL.
Scan llne number are lncreaslng from boLLom Lo Lop.
Loadlng a specled colour lnLo frame
buffer aL a plxel posluon dened by
column 'x' along scan llne 'y'
seLlxel (x, y)
CurrenL frame-buffer lnLenslLy for a
specled locauon can be accompllshed
geLlxel (x, y)
Pixel
column No
S
c
a
n

L
i
n
e

N
o

0
0 1 2
1
2
Llne Scan-Converslon.3
Llne ls dened by Lwo end polnLs
1
,
2
and Lhe equauon of llne
as shown ln Lhe llgure
1hese can be ploLLed or scan-converLed uslng dlfferenL llne
ploLung algorlLhms.
1he slope-lnLercepL equauon ls
noL sulLable for verucal llnes.
PorlzonLal, verucal and dlagonal
(|m| = 1) llnes can be handled as
speclal cases and can be mapped
Lo lmage space sLralghLforward.
y
b
y = m.x + b
P (x , y )
1 1 1
P
2
(x
2
, y
2
)
x
Llne urawlng AlgorlLhms
ulrecL use of llne equaLlon
uuA algorlLhm
8resenham's Llne AlgorlLhm
ulrecL use of Llne equauon
ulrecL approach
1he CarLeslan slope
lnLercepL equauon for a
sLralghL llne:
y = m . x + b (1)
'm' represenLs slope of
Lhe llne and 'b' ls
lnLercepL on y-axls, such
LhaL
(2)
(3) b = y
1
" m . x
1
x
2
" x
1
y
2
" y
1
m =
y
1
y
2
x
1
x
2
y
2
y
1
x
1
x
2
ulrecL use of Llne equauon..1
lor a small change ln 'x'
al ong L he l l ne, L he
correspondlng change ln
'y' can be glven by
Ay = m. Ax (4)
or Ax = Ay/m (3)
- 1hese equauons form
L h e b a s l s f o r
d e L e r ml n l n g L h e
deecuon volLages ln
analog devlces.
lor llnes wlLh slope|m|<1,
!x ls seL proporLlonal Lo
small horlzonLal deecLlon
volLage and Lhe
correspondlng verLlcal
deecLlon ls Lhen seL
proporLlonal Lo !y as
calculaLed from Lhe
equauon (4).
ulrecL use of Llne equauon.2
lor l l nes wl Lh sl ope
magnlLudes |m|>1, !y ls
seL proporLlonal Lo a small
verLlcal deecLlon volLage
and Lhe correspondlng
horlzonLal deecLlon ls
Lhen seL proporLlonal Lo
!x as calculaLed from
Lhe equauon (3).
lor llnes wlLh slope
magnlLudes m=1, Ay =
Ax and Lhe horlzonLal
and verLlcal deecLlon
volLage are equal
ulrecL use of Llne equauon.3
1hls means:
llrsL scan converL end polnLs Lo plxel locauons (x
1
', y
1
') and
(x
2
', y
2
')
SeL 'm' and 'b' uslng equauons
lor |m|! 1, for lnLeger value of x beLween and excludlng
x
1
', x
2
', calculaLe Lhe correspondlng value of y and scan-
converL (x, y)
lor |m|> 1, for lnLeger value of y beLween and excludlng
y
1
', y
2
', calculaLe Lhe correspondlng value of x and scan-
converL (x, y)
ulrecL use of Llne equauon.4
Lxample:
Lnd polnLs are (0, 0) and (6, 18). CompuLe each
value of x as y sLeps from 0 Lo 18 and ploL.
lor equauon y = m.x + b, compuLe slope as
m = Ay /Ax
uslng value of 'm' compuLe 'b'
lace y = 1 Lo 17 and compuLe correspondlng
value of 'x'
loL
ulrecL use of Llne equauon.3
Lxample:
m = (18 - 0) /(6 - 0) = 3 m > 1 b = 0
Change y: compuLe for y = 1 Lhe value of x = Ay/m = 1/3
CarLeslan coordlnaLe polnL (1, 0.3)
lxel coordlnaLe polnL (Case-l): (1, 0)
lxel coordlnaLe polnL (Case-ll): (1, 0)
CompuLe for y = 2 Lhe value of x = 2/3
CarLeslan coordlnaLe polnL (1, 0.67)
lxel coordlnaLe polnL (Case-l): (1, 0)
lxel coordlnaLe polnL (Case-ll): (1, 1)
loL Lhe Lhree graphs
Conunue ...
ulglLal ulfferenual Analyzer (uuA)
uuA ls an lncremenLal scan-converslon llne algorlLhm
based on calculaung elLher Ay or Ax as menuoned ln
llne prlmluves.
Suppose aL sLep 'l' Lhe polnL ls (x
l
, y
l
) on Lhe llne.
lor nexL polnL (x
l+1
, y
l+1
)
y
l+1
= y
l
+ Ay, where Ay = m. Ax
x
l+1
= x
l
+ Ax, where Ax = Ay/m
1he process conunues unul x reaches x
2
' (for |m|! 1 case)
or y reaches y
2
' (for |m|> 1 case)
ulglLal ulfferenual Analyzer.1
Conslder a llne wlLh poslLlve slope. LeL Lhe slope be
less Lhan or equal Lo 1. lor unlL lnLerval Ax=1,
y
k+1
= y
k
+ m, where k = 1, 2, .., end polnL (6)
1he value of y
k+1
should be rounded Lo Lhe nearesL lnLeger
lor slope greaLer Lhan 1, lncreaslng Ay by 1
x
k+1
= x
k
+ 1/m, where k = 1, 2, .., end polnL (7)
1he value of x
k+1
should be rounded Lo Lhe nearesL lnLeger
ulglLal ulfferenual Analyzer.2
1he assumpLlon here ls LhaL llnes are processed from
le Lo rlghL. lf lL ls processed from rlghL Lo le Lhen
y
k+1
= y
k
- m
x
k+1
= x
k
- 1/m
(8)
(9)
x
y
ulglLal ulfferenual Analyzer.3
lor negaLlve slope of llne as shown ln flgure:
lf movlng from le Lo rlghL:
SeL Ax = +1 and use equauon (8) for m<1 Lo calculaLe y values
SeL $y = -1 and use equauon (7) for m>1 Lo calculaLe x values
lf movlng from rlghL Lo le:
lf m < 1 Lhen seL Ax = -1 and obLaln y
values from equauon (6)
lf m > 1 Lhen seL Ay = +1 and obLaln x
values from equauon (9)
x
y
ulglLal ulfferenual Analyzer.4
1hls algorlLhm ls fasLer ln calculaLlng plxel poslLlons
8oundlng off ln successlve addlLlons and lLs
accumulauon may cause drllng of Lhe plxel posluon
away from Lhe Lrue llne
1hls roundlng off procedure ls also Llme consumlng
8y converLlng m or 1/m lnLo lnLeger or fracuonal
parL, Lhe ume consumed can be reduced.

Vous aimerez peut-être aussi