raster graphics - iit delhi

25
Raster Graphics Rasterization Drawing Algorithms Pixelization Scan Conversion Continuous Discrete

Upload: others

Post on 28-Nov-2021

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Raster Graphics - IIT Delhi

Raster Graphics

Rasterization

Drawing Algorithms

Pixelization Scan Conversion

Continuous Discrete

Page 2: Raster Graphics - IIT Delhi

Raster Graphics

DDA (Digital Differential Analyzer)

Line Drawing Algorithms

Line Equation:

(x1,y1)

(x2,y2)

Δx

Δy

Bmxy +=

1212

xy

xxyy

dxdym

ΔΔ

===--

Page 3: Raster Graphics - IIT Delhi

Raster Graphics

Line Drawing Algorithms

BxxmyBmxy

Bmxy

iiii

ii

+Δ+=+=

+=

+

++)(1

11

DDA (Digital Differential Analyzer)

(x1,y1)

(x2,y2)

Δx

Δy

Page 4: Raster Graphics - IIT Delhi

Raster Graphics

Line Drawing Algorithms

1

1 if

11

myyxx

x

iiii+=+=

+

+

DDA (Digital Differential Analyzer)

(x1,y1)

(x2,y2)

Δx

Δy

Page 5: Raster Graphics - IIT Delhi

Raster Graphics

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: Raster Graphics - IIT Delhi

Raster Graphics

DDA (Digital Differential Analyzer)

Line Drawing Algorithms

m <= 1 m > 1

Exchange the role of x and y

Page 7: Raster Graphics - IIT Delhi

Raster Graphics

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: Raster Graphics - IIT Delhi

Raster Graphics 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: Raster Graphics - IIT Delhi

Raster Graphics 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: Raster Graphics - IIT Delhi

Raster Graphics 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: Raster Graphics - IIT Delhi

Raster Graphics 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: Raster Graphics - IIT Delhi

Raster Graphics 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: Raster Graphics - IIT Delhi

Raster Graphics 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: Raster Graphics - IIT Delhi

Raster Graphics

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: Raster Graphics - IIT Delhi

Raster Graphics Midpoint Circle Algorithm

(x,y)

222 Ryx =+

Page 16: Raster Graphics - IIT Delhi

Raster Graphics Midpoint Circle Algorithm

(x,y)

222 Ryx =+

Page 17: Raster Graphics - IIT Delhi

Raster Graphics Midpoint Circle Algorithm

(x,y)

Page 18: Raster Graphics - IIT Delhi

Raster Graphics 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: Raster Graphics - IIT Delhi

Raster Graphics 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: Raster Graphics - IIT Delhi

Raster Graphics 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: Raster Graphics - IIT Delhi

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

Raster Graphics

M

E

SE M’’

M’

P(xp, yp)

Page 22: Raster Graphics - IIT Delhi

Midpoint Circle Algorithm

Consider II octant

Raster Graphics

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: Raster Graphics - IIT Delhi

Midpoint Circle Algorithm

Consider II octant

Raster Graphics

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: Raster Graphics - IIT Delhi

Midpoint Circle Algorithm

Consider II octant

Raster Graphics

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: Raster Graphics - IIT Delhi

Ellipse Drawing Algorithm

Raster Graphics

E

SE

S SE

1=by+

ax

2

2

2

2