drawing algorithms - ernetpkalra/col781/slides/raster... · 2018-01-09 · midpoint line algorithm...
TRANSCRIPT
Rasterization
Drawing Algorithms
Pixelization Scan Conversion
Continuous Discrete
DDA (Digital Differential Analyzer)
Line Drawing Algorithms
Line Equation:
(x1,y1)
(x2,y2)
Δx
Δy
Bmxy +=
1212
xy
xxyy
dxdym
ΔΔ
===--
Line Drawing Algorithms
BxxmyBmxy
Bmxy
iiii
ii
+Δ+=+=
+=
+
++)(1
11
DDA (Digital Differential Analyzer)
(x1,y1)
(x2,y2)
Δx
Δy
Line Drawing Algorithms
1
1 if
11
myyxx
x
iiii+=+=
=Δ
+
+
DDA (Digital Differential Analyzer)
(x1,y1)
(x2,y2)
Δx
Δy
DDA (Digital Differential Analyzer)
Line Drawing Algorithms
(xi, round(yi) )
y = y1
for (x = x1; x ≤ x2; x ++){ Writepixel(x, round (y)); y+ =m;}
DDA (Digital Differential Analyzer)
Line Drawing Algorithms
m <= 1 m > 1
Exchange the role of x and y
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
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,
Midpoint Line Algorithm
M
NE
E
Line M’’
M’
P(xp,yp)
Bdx)c dx,b dy,(a0
0),(
line Consider1m0Let
====+
=++=
+=
<<=
-Bdxydxxdy
cbyaxyxF
Bxdxdyy
-
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
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
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)
Midpoint Line Algorithm
)(2),(
(division) 2
-dy=2
2
)21()1()
21,1(
:startAt
00
0000
cbyaxyxF
dxbad
bacbyaxd
cybxayxFd
start
start
start
++=
+=
++++=
++++=++=
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
NΔ
Δ≤
ΔΔ
Midpoint Line Algorithm
Midpoint Circle Algorithm
(x,y)
222 Ryx =+
Midpoint Circle Algorithm
(x,y)
222 Ryx =+
Midpoint Circle Algorithm
(x,y)
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
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 +=),(
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)
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)
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)
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)
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
<
Ellipse Drawing Algorithm
E
SE
S SE
1=by+
ax
2
2
2
2