Professional Documents
Culture Documents
Basic Raster Graphics Algorithms For 2D Drawing: Materi 02 - Komputer Grafik-2018/2019 - 3
Basic Raster Graphics Algorithms For 2D Drawing: Materi 02 - Komputer Grafik-2018/2019 - 3
Basic Raster Graphics Algorithms For 2D Drawing: Materi 02 - Komputer Grafik-2018/2019 - 3
ALGORITHMS FOR 2D
DRAWING
Materi 02 – Komputer Grafik- 2018/2019 - 3
Raster Display:
1
Primitive element: pixel
Raster: A rectangular array of points or dots
Pixel: One dot or picture element of the raster
Scan line: A row of pixels
p(x, y)
O x
Line Drawing
7
p(12, 20)
p(3, 8)
x
Line Drawing
8
Constant slope: y
O x m
x
Note that in order to implement the above algorithm, the slope m has to be
between 0 and 1; then we are able to step along x axis; otherwise, we
must reverse the roles of x and y and assigning a unit step to y and
incrementing x by x = y/m = 1/m.
14
Solution
15
P (x1,y1)
Let’s consider the explicit form of the
dy=y1-y0
line: y = mx + B.
We have P (x0,y0)
F(x,y) = dy x – dx y + B dx = 0. dx=x1 – x0
Compare with the implicit form
dy y1 y0
F(x,y) = ax + by + c = 0 m
We have a = dy, b = -dx, and c = B dx x1 x0
dx.
(xp+1, yp+1)
NE (xp+2, yp+1)
1 Q 1
d old F ( x p 1, y p ) d new F ( x p 2, y p )
2 M 2
(xp , yp)
E
(xp +1, yp) (xp +2, yp)
19
Summary to the midpoint technique (cont.)
20
…
Lines: Some Remarks
23
Finite
Solution:
25
Example of DDA algorithm
a single DDA for the first quadrant:
26 line from (0,0 ) to (5,5)
Example of DDA algorithm
a single DDA for the first quadrant:
27 line from (0,0) to (8,4)
Bresenham Algorithm
28
Basic idea:
29
Example of Bresenham algorithm
line from (0,0) to (5,5)
30
Flowchart of Bresenham
31
32
Conditions for general Bresenham’s
algorithm
33
34
Example of Bresenham
algorithm
35 line from (0,0) to (8,4)