Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
(Previous)
NE (next)
E (next)
1he Mld 9olnL
mldpolnL
-
prevlous
C
5
x x
5
x x
5
y y
5
y y
M
1he Mld 9olnL
mldpolnL
-
prevlous
C
5 5
y x
5 5
y x
5 5
y x
5 5
y x
1he y coordlnaLe on Lhe maLhemaLlcal llne aL x
k
ls
uerlvlng 1he 8resenham Llne AlgorlLhm
W AL sample poslLlon x
k
/
407
/
:5507
W So /
:5507
and /
407
are glven as follows
W and
W We can use Lhese Lo make a slmple declslon
abouL whlch plel ls closer Lo Lhe maLhemaLlcal
llne
uerlvlng 1he 8resenham Llne AlgorlLhm (conL)
k 407
y y /
k k
y - x m
y y /
k :5507
- x m y
k k
W 1hls slmple declslon ls based on Lhe dlfference
beLween Lhe Lwo plel poslLlons
W LeL's subsLlLuLe m wlLh y/x where x and
y are Lhe dlfferences beLween Lhe endpolnLs
uerlvlng 1he 8resenham Llne AlgorlLhm (conL)
- y x m / /
k k :5507 407
- y x
x
y
x / / x
k k :5507 407
c c - x y y x x y
k k
c y x x y
k k
c c
W So a declslon parameLer 5
k
for Lhe kLh sLep
along a llne ls glven by
W 1he slgn of Lhe declslon parameLer 5
k
ls Lhe
same as LhaL of /
407
/
:5507
W lf 5
k
ls negaLlve Lhen we choose Lhe lower
plel oLherwlse we choose Lhe upper plel
uerlvlng 1he 8resenham Llne AlgorlLhm (conL)
c y x x y
/ / x 5
k k
:5507 407 k
c c
W emember coordlnaLe changes occur along
Lhe x als ln unlL sLeps so we can do
everyLhlng wlLh lnLeger calculaLlons
W AL sLep k+1 Lhe declslon parameLer ls glven as
W SubLracLlng 5
k
from Lhls we geL
uerlvlng 1he 8resenham Llne AlgorlLhm (conL)
c y x x y 5
k k k
c c
k k k k k k
y y x x x y 5 5
W 8uL x
k
ls Lhe same as x
k
so
W where y
k1
y
k
ls elLher 0 or 1 dependlng on
Lhe slgn of 5
k
W 1he flrsL declslon parameLer p0 ls evaluaLed aL
(0 y0) ls glven as
uerlvlng 1he 8resenham Llne AlgorlLhm (conL)
k k k k
y y x y 5 5
x y 5
uerlvaLlon (SLep 1)
W Clven Lwo endpolnLs (AAy) and (88y) Cne can be chosen as Lhe sLarL
polnL ( (k)y(k) ) 1he cholce ls purely arblLrary
W lrom Lhls sLarL polnL we have elghL posslble cholces for Lhe neL plel ln
Lhe llne We need Lo lsolaLe Lhese elghL cholces lnLo only Lwo
W lf we resLrlcL Lhe slope for now Lo (0 slope 1) and assume
(A 8)
W we know LhaL we can slmply step ln one plel aL a Llme Lo Lhe rlghL and
deLermlne whaL y value Lo choose neL Clven ( (k)y(k) ) Lhe neL lJeol
polnL wlll be ( (k)+1 y ) where y m*((k)+1) + b
W 8uL we musL choose beLween ( (k)+1 y(k) ) or ( (k)+1 y(k)+1 ) 1hese
polnLs represenL Lhe one [usL Lo Lhe rlghL and Lhe one Lo Lhe rlghL and one
up respecLlvely
uerlvaLlon (SLep 2)
W Pow do we declde beLween Lhese polnLs? We now have Lhe
followlng
sLarL polnL ( x(k) y(k) )
W -eL Lwo avallable polnLs
( x(k)+1 y(k) ) and ( x(k)+1 y(k)+1 )
W LocaLlon of neL lJeol polnL
( x(k)+1 y ) where y m*(x(k)+1) + b (9olot5lope lloe epootloo)
W We musL choose Lhe closesL polnL Lo Lhe lJeol So flrsL we musL flnd
Lhe dlsLances Lo Lhe Lwo avallable cholces from Lhe ldeal locaLlon
uerlvaLlon (SLep 3)
W ulsLance beLween polnLLorlghL and ldeal
1 y y(k) (rlghL polnL)
W ulsLance beLween polnLLorlghLandup and ldeal
(y(k)+1) y (upper polnL Lo Lhe rlghL)
W So we can slmply choose subsequenL polnLs based on
Lhe followlng
lf (d1d2) Lhen choose polnLLorlghL ( (k)+1 y(k) )
lf (d1d2) Lhen choose polnLLorlghLandup ( (k)+1 y(k)+1 )
W Powever slnce we are Lrylng Lo develop a lAS1 way of
dolng Lhls we wlll noL be comparlng Lhese values ln
such a manner lnsLead we wlll creaLe a Jeclsloo
votloble LhaL can be used Lo qulckly deLermlne whlch
polnL Lo use
2 3 4 3
2
4
3
3
uerlvaLlon (SLep 4)
W Pow do we creaLe Lhls Jeclsloo votloble?
W llrsL lnsLead of comparlng Lhe Lwo values Lo each oLher we
can slmply evaluaLe (d1d2) and slmply LesL Lhe slgn Lo
deLermlne whlch Lo choose Make sense?
W lf d1 d2 Lhen (d1d2) wlll be poslLlve eLc So now lf (d1
d2) ls poslLlve (greaLer Lhan zero) choose polnLLorlghL
andup C lf (d1d2) ls negaLlve or zero (less Lhan or equal
Lo zero) choose polnLLorlghL
W 1hls ls nlce and clear buL we musL compllcaLe Lhlngs a llLLle
ln order Lo geL a LAL speedups
uerlvaLlon (SLep 3)
W LvaluaLe (d1d2) as follows
(1) y y(k) ( (y(k)+1) y ) y y(k) (y(k)+1) + y
W -ow subsLlLuLe uslng
y m*(x(k)+1) + b
(1) m*(x(k)+1) + b y(k) (y(k)+1) + m*(x(k)+1) + b
(1) *m*(x(k)+1) *y(k) + *b 1
uerlvaLlon (SLep 6)
W educe Lhls evaluaLlon by flndlng and
subsLlLuLlng
slope m d?/dx where
d? abs(8y Ay) and dx abs(8 A)
W So now
(d1d2) *($O)*(x(k)+1) *y(k) + *b 1
W Lpand flrsL Lerm so
(d1d2) *($O)*x(k) + *($O) *y(k) + *b 1
uerlvaLlon (SLep 7)
W 1o slmpllfy Lhls epresslon we wlll creaLe a new declslon varlable 9(k)
9(k) O * (1)
W 1hls ls wlll remove Lhe dlvlslons and wlll sLlll keep Lhe
same slgn for Lhe declslon Why? 8ecause dx ls always poslLlve!
W LvaluaLe 9(k) as follows
9(k) dx * ( *($O)*x(k) + *($O) *y(k) + *b 1 )
9(k) **x(k) + * *O*y(k) + *O*b O
W earrange Lerms Lo geL
9(k) **x(k) *O*y(k) + * + *O*b O C
9(k) **x(k) *O*y(k) + c where consLanL
c 2*d? + dx*(2*b 1)
(Lhls remalns consLanL regardless of cholce of and y Lhls noLaLlon alds ln
compuLaLlon of d9)
uerlvaLlon (SLep 8)
W We have a declslon varlable LhaL can be calculaLed very
qulckly buL lL sLlll requlres a compleLe evaluaLlon of
9(k) for each polnL along Lhe llne
W Slnce changes ln 9(k) wlll be llnear we can evaluaLe
subsequenL 9(k) values loctemeotoll by flndlng a
consLanL change ln 9(k) for each subsequenL polnL
W Pow? 8y evaluaLlng an lncremenLal change ln Lhe
declslon funcLlon uslng otwotJulffeteocloq chang
|n
9 9 9(k+1) 9(k)
uerlvaLlon (SLep 9)
W d9 ls evaluaLed as follows
9(k+1) 9(k) 2*d?*(k+1) 2*dx*y(k+1) + c 2*d?*(k) + 2*dx*y(k) c
2*d?*(k+1) 2*d?*(k) 2*dx*y(k+1) + 2*dx*y(k)
**(x(k+1) x(k)) *O*(y(k+1) y(k))
W Cbserve LhaL slnce we are sLepplng ln (by 1)
(x(k+1) x(k)) 1
W So wlLh subsLlLuLlon
9 * *O*(y(k+1) y(k))
W 1here are Lwo posslblllLles for (y(k+1) y(k)) 0 or 1 dependlng on lf we
choose polnLLorlghL or polnLLorlghLandup
9 * *O*(0) * lf polnLLorlghL ls chosen
9 * *O*(1) * *O lf polnLLorlghLandup ls chosen
uerlvaLlon (SLep 10)
W -ow we know how much Lo lncremenL Lhe declslon varlable based on Lhe
polnL chosen buL now we musL flnd Lhe lnlLlal declslon value 9(0) We
musL evaluaLe uslng Lhe luLL equaLlon (wlLh consLanL) for 9(k)
9(k) 2*d?*(k) 2*dx*y(k) + 2*d? + dx*(2*b 1)
9(0) 2*d?*(0) 2*dx*y(0) + 2*d? + dx*(2*b 1)
W WhaL ls b? uslng Lhe polnLslope llne equaLlon y(0) m*(0) + b
so b y m*x(0) subsLlLuLe b
9(0) 2*d?*(0) 2*dx*y(0) + 2*d? + dx*(2*(y(0) m*(0)) 1)
W SubsLlLuLe m d?/dx
9(0) 2*d?*(0) 2*dx*y(0) + 2*d? + dx*(2*(y(0) (d?/dx)*(0)) 1)
9(0) 2*d?*(0) 2*dx*y(0) + 2*d? + 2*dx*(y(0) (d?/dx)*(0)) dx
9(0) 2*d?*(0) 2*dx*y(0) + 2*d? + 2*dx*(y(0) (d?/dx)*(0)) dx
9(0) 2*d?*(0) 2*dx*y(0) + 2*d? + 2*dx*y(0) 2*d?*(0) dx
9(0) * O
9(k) **x(k) *O*y(k) + * + *O*b O
uerlvaLlon (SLep 11)
W 1he enLlre algorlLhm has been derlved We have Lhe
followlng Lools Lo generaLe a llne (only ln Lhe flrsL ocLanL)
1he endpolnLs (Ax Ay) and (8x 8y)
hange ln O ab(8x Ax)
hange ln y ab(8y Ay)
SLarL polnL (chosen arblLrarlly) (Ax Ay)
lnlLlal declslon value 9(0) * O
9olnL cholce condlLlons
W |f (9 0) choose polnLLorlghL
W |f (9 0) choose polnLLorlghLandup
lncremenLs ln 9 (d9) based on cholces
W lf polnLLorlghL ls chosen lncremenL 9 by (*)
W lf polnLLorlghLandup ls chosen lncremenL 9 by (*) (*O)
1he 8resenham Llne AlgorlLhm
8LSL-PAM'S Ll-L uAWl-C ALCCl1PM
(for |m| 10)
1 lnpuL Lhe Lwo llne endpolnLs sLorlng Lhe lefL endpolnL ln
x
0
, y
0
y 5 5
k k
(21,11) 5 (2,15)
1 2 (22,12) 2 (27,1)
2 -2 (23,12) 7 -2 (28,1)
3 14 (24,13) 8 14 (29,17)
4 1 (25,14) 9 1 (3,18)
Lample