25
Rasterization Drawing Algorithms Pixelization Scan Conversion Continuous Discrete

Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

  • Upload
    others

  • View
    21

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Rasterization

Drawing Algorithms

Pixelization Scan Conversion

Continuous Discrete

Page 2: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

DDA (Digital Differential Analyzer)

Line Drawing Algorithms

Line Equation:

(x1,y1)

(x2,y2)

Δx

Δy

Bmxy +=

1212

xy

xxyy

dxdym

ΔΔ

===--

Page 3: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Line Drawing Algorithms

BxxmyBmxy

Bmxy

iiii

ii

+Δ+=+=

+=

+

++)(1

11

DDA (Digital Differential Analyzer)

(x1,y1)

(x2,y2)

Δx

Δy

Page 4: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Line Drawing Algorithms

1

1 if

11

myyxx

x

iiii+=+=

+

+

DDA (Digital Differential Analyzer)

(x1,y1)

(x2,y2)

Δx

Δy

Page 5: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

DDA (Digital Differential Analyzer)

Line Drawing Algorithms

(xi, round(yi) )

y = y1

for (x = x1; x ≤ x2; x ++){ Writepixel(x, round (y)); y+ =m;}

Page 6: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

DDA (Digital Differential Analyzer)

Line Drawing Algorithms

m <= 1 m > 1

Exchange the role of x and y

Page 7: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Line Algorithm

Line Drawing Algorithms

M

NE

E

Line

above

below

Find on what side of the line the mid point is: If below then NE is closer to line If above then E is closer to line

Page 8: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Line Algorithm

M

NE

E

Line M’’

M’

P(xp,yp)

line above y)(x, : 0<y)F(x,linebelow y)(x,: 0>y)F(x,

line on y)(x,: 0=y)F(x,

Page 9: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Line Algorithm

M

NE

E

Line M’’

M’

P(xp,yp)

Bdx)c dx,b dy,(a0

0),(

line Consider1m0Let

====+

=++=

+=

<<=

-Bdxydxxdy

cbyaxyxF

Bxdxdyy

-

Page 10: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Line Algorithm

M

NE

E

Line M’’

M’

P(xp,yp)

E choose line, the above is M 0 d ifNE choose line, thebelow is M 0 > d if

)21()1(

)21,1()(

<

++++=

=++=

cybxad

dyxFMF

pp

pp

Page 11: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Line Algorithm

Line M

NE

E

M’’

M’

P(xp,yp)

dyadd

cybxad

cybxad

yxFMFd

oldnewE

ppold

ppnew

ppnew

===

++++=

++++=

++==

Δ -

)21()1(

)21()2(

)21,2()'(

:E When

Page 12: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Line Algorithm

Line

dxdybadd

cybxad

cybxad

yxFMFd

oldnewNE

ppold

ppnew

ppnew

--

)21()1(

)23()2(

)23,2()''(

:NE When

=+==

++++=

++++=

++==

Δ

M

NE

E

M’’

M’

P(xp,yp)

Page 13: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Line Algorithm

)(2),(

(division) 2

-dy=2

2

)21()1()

21,1(

:startAt

00

0000

cbyaxyxF

dxbad

bacbyaxd

cybxayxFd

start

start

start

++=

+=

++++=

++++=++=

Page 14: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Whileendy);(x,Writepixel

end1;= y+1;=x+ E;=d+

else1;=x+ E;=d+

0d ifx2) < (x While

y);(x,Writepixely1;= yx1;=x

dx);-2(dy=NE 2dy;=E dx;-2dy=dy1;-y2=dy x1;-x2=dx

Δ≤

ΔΔ

Midpoint Line Algorithm

Page 15: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Circle Algorithm

(x,y)

222 Ryx =+

Page 16: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Circle Algorithm

(x,y)

222 Ryx =+

Page 17: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Circle Algorithm

(x,y)

Page 18: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Circle Algorithm

(x,y)

(y,x)

(y,-x)

(-x,y)

(-y,x)

(-y,-x)

(-x,-y) (x,-y)

8-way symmetry: drawing in one octant is enough

Page 19: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Circle Algorithm

Consider II octant

M

E

SE M’’

M’

P(xp, yp)

circle inside y)(x, : 0<y)F(x,circle outside y)(x,: 0>y)F(x,

circle on y)(x,: 0=y)F(x,y)(x,point given a For

222 - RyxyxF +=),(

Page 20: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Circle Algorithm

SE Choose circle) outside (M 0 > If

E Choose circle) inside (M 0 < If

F(M) Evaluate

Consider II octant

M

E

SE M’’

M’

P(xp, yp)

Page 21: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

32

)21()2(

)21,2()'(

)0(d E When

)21()1(

)21,1()(

222

old

222

+=−=

−−++=

−+==

<

−−++=

−+==

Δ poldnewE

pp

ppnew

pp

ppold

xdd

Ryx

yxFMFd

Ryx

yxFMFd

Midpoint Circle Algorithm

Consider II octant

M

E

SE M’’

M’

P(xp, yp)

Page 22: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Circle Algorithm

Consider II octant

522

)23()2(

)23,2()''(

)0(d SE When

222

old

+−=−=

−−++=

−+==

Δ ppoldnewSE

pp

ppnew

yxdd

Ryx

yxFMFdM

E

SE M’’

M’

P(xp, yp)

Page 23: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Circle Algorithm

Consider II octant

RRF

Initial

−=−45)

21,1(

)21 -R (1,=point midnext

point,start R) (0,Condition

M

E

SE M’’

M’

P(xp, yp)

Page 24: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Midpoint Circle Algorithm

Consider II octant

Whileendy);(x,Writepixel

end1;= y-1;=x+ 5;+2y-2x=d+

else1;=x+ 3;+2x=d+

0d ifdo x) > (y Whiley);(x,Writepixel

R;-45=dR;= y0;=x

<

Page 25: Drawing Algorithms - ERNETpkalra/col781/slides/raster... · 2018-01-09 · Midpoint Line Algorithm Line Drawing Algorithms M NE E Line above below Find on what side of the line the

Ellipse Drawing Algorithm

E

SE

S SE

1=by+

ax

2

2

2

2