Professional Documents
Culture Documents
David Mario Yohanes Samosir - Resume
David Mario Yohanes Samosir - Resume
LINE
COMPUTER GRAPICHS
Supporting Lecturer:
Putu Hendra Suputra, S.Kom., M.Cs.
Arranged By:
David Mario Yohanes Samosir 2115101055
IKI
COMPUTER SCIENCE
INFORMATIC ENGINEERING MAJOR
GANESHA UNIVERSITY OF EDUCATION
2023
Explain the definition, working methods, and advantages and disadvantages of using Bruteforce,
DDA, Bresenham algorithms in line generation.
A. Definition
A simple but slow
approach to line generation
in computer graphics,
examines and decides each
pixel sequentially in the
Definition line trajectory, determining
whether it should be
Bruteforce
coloured or not by
calculating the relationship
between the pixel position
and the actual line.
Checks all pixels, high
Characteristic precision, low performance
on long lines.
The DDA algorithm uses
simple maths to create a
line between two points. It
works by moving a fixed
Definition
number of steps in x and y
DDA (Digital Differential
coordinates, creating a line
Analyzer)
with few restrictions on
precision.
Limited precision, good
Characteristic performance on straight
line, efficient
An efficient line drawing
algorithm that is very
popular in computer
graphics, utilises fast
mathematical calculations
Definition to determine the pixel
points that should be filled
Bresenham
in the line trajectory, so it
works well on high-
resolution lines and with
limited resources.
Efficient, good precision,
Characteristic suitable for line drawing on
pixel-based screens.
B. Working Methods
1. Bruteforce
The steps in drawing a line using the Brute Force Algorithm are as follows:
a. Determine the two endpoints, starting point and endpoint (𝑥1 , 𝑦1 ) 𝑑𝑎𝑛 (𝑥1 , 𝑦1 )
b. If 𝑥1 = 𝑥2 (the line formed is vertical), then
i. y= y +1 and x remains
ii. Draw the point (x,y) on the screen
iii. Done
c. If 𝑦1 = 𝑦2 (the line formed is horizontal), then
i. x = x +1 and y remains
ii. Draw the point (x,y) on the screen
iii. Done
d. If, steps b and c are not met, then calculate the slope or gradient of the line
𝑦 − 𝑦
𝑚= 2 1
𝑥2 − 𝑥 1
e. N = 𝑥2 − 𝑥1 + 1
f. 𝑥 = 𝑥1
g. Repeat N times:
i. 𝑦 = 𝑚 ( 𝑥 − 𝑥1 ) + 𝑦1
ii. If the value of y is a fractional number, then, do rounding 𝑦𝑎 = 𝑅𝑜𝑢𝑛𝑑(𝑦)
iii. Draw Point ( 𝑥, 𝑦𝑎 )on the screen
iv. 𝑥 =𝑥+1
h. Done
Settlement:
Horizontal Line (Brute Force):
Draw a horizontal line from (2, 4) to (8, 4) using the Brute Force algorithm.
a. Point (𝑥1 , 𝑦1 ) = ( 2,4 ) and ( 𝑥2 , 𝑦2 ) = ( 8,4 )
b. Not fulfilled
c. 4 = 4 (the line formed is horizontal)
d. 𝑁 = 𝑥2 − 𝑥1 + 1
i. 𝑁 = 8 − 2 + 1
ii. 𝑁 = 7
e. Repeat N for 7 times
Iteration to 𝑥 𝑦(𝑎) (𝑥, 𝑦(𝑎))
1 𝑥= 2 𝑦=4 ( 2,4 )
2 𝑥 = 𝑥+1 𝑦=4 ( 3,4 )
𝑥 = 2+1
𝑥=3
3 𝑥 = 𝑥+1 𝑦=4 ( 4,4 )
𝑥 = 3+1
𝑥=4
4 𝑥 = 𝑥+1 𝑦=4 ( 5,4 )
𝑥 = 4+1
𝑥=5
5 𝑥 = 𝑥+1 𝑦=4 ( 6,4 )
𝑥 = 5+1
𝑥=6
6 𝑥 = 𝑥+1 𝑦=4 ( 7,4 )
𝑥 = 6+1
𝑥=7
7 𝑥 = 𝑥+1 𝑦=4 ( 8,4 )
𝑥 = 7+1
𝑥=8
Bruteforce
Horizontal
x1 2 x2 8
y1 4 y2 4
BRUTEFORCE
Iteration x y(a) (x,y(a)) 5
1 2 4 2,4 4
2 3 4 3,4 3
3 4 4 4,4
2
4 5 4 5,4
5 6 4 6,4 1
6 7 4 7,4 0
2 3 4 5 6 7 8
7 8 4 8,4
1 𝑥=2 𝑦= 1 ( 2, 1)
𝑦 = 1+1
2 𝑥=2 ( 2, 2 )
𝑦=2
𝑦 = 2+1
3 𝑥=2 ( 2, 3 )
𝑦=3
𝑦 = 3+1
4 𝑥=2 ( 2, 4 )
𝑦=4
𝑦 = 4+1
5 𝑥=2 ( 2, 5 )
𝑦=5
𝑦 = 5+1
5 𝑥=2 ( 2, 6 )
𝑦=6
Bruteforce Vertical
x1 2 x2 2 BRUTEFORCE
y1 1 y2 6 7
6
Iteration x y(a) (x,y(a)) 5
1 2 1 2,1 4
2 2 2 2,2 3
3 2 3 2,3 2
4 2 4 2,4 1
0
5 2 5 2,5
0 0,5 1 1,5 2 2,5
6 2 6 2,6
Settlement:
Diagonal Line (DDA)
Draw a horizontal line from (2, 1) to (9,6) using the DDA algorithm
1 Start point ( 2, 1 ) and end point ( 9, 6 )
2 Count
a. 𝑑𝑥 = 𝑥2 − 𝑥1
𝑑𝑥 = 9 − 2
𝑑𝑥 = 7
b. 𝑑𝑦 = 𝑦2 − 𝑦1
𝑑𝑥 = 6 − 1
𝑑𝑥 = 5
3 Determine 𝑠𝑡𝑒𝑝
a. Because |𝑑𝑥| > |𝑑𝑦|
7>6
Then 𝑠𝑡𝑒𝑝 = |𝑑𝑥|
𝑠𝑡𝑒𝑝 = 7
4 Calculate the change in pixel coordinates with the following equation:
𝑑𝑥
a. 𝑥𝑖𝑛𝑐 = 𝑠𝑡𝑒𝑝
7
𝑥𝑖𝑛𝑐 = =1
7
𝑑𝑦
b. 𝑦𝑖𝑛𝑐 = 𝑠𝑡𝑒𝑝
5
𝑦𝑖𝑛𝑐 = = 0,71
7
Iteratio 𝑥 𝑦 𝑢 𝑣 ( 𝑢, 𝑣 )
n to
1 𝑥 = 𝑥 + 𝑥𝑖𝑛𝑐 𝑦 = 𝑦 + 𝑦𝑖𝑛𝑐 3 2 ( 3, 2 )
𝑥 =2+ 1 𝑦 = 1 + 0,71
𝑥=3 𝑦 = 1,71
2 𝑥 = 𝑥 + 𝑥𝑖𝑛𝑐 𝑦 = 𝑦 + 𝑦𝑖𝑛𝑐 4 2 ( 4, 2 )
𝑥 =3+ 1 𝑦 = 1,71 + 0,71
𝑥=4 𝑦 = 2,42
3 𝑥 = 𝑥 + 𝑥𝑖𝑛𝑐 𝑦 = 𝑦 + 𝑦𝑖𝑛𝑐 5 3 ( 5, 3 )
𝑥 =4+ 1 𝑦 = 2,42 + 0,71
𝑥=5 𝑦 = 3,13
Digital Differential
Analyzer (DDA)
x1 2 x2 9
y1 1 y2 6 DIGITAL
DIFFERENTIAL
1
ANALYZER (DDA)
0,71 7
6
Iteration x y u v (u,v) 5
1 3 1,71 3 2 3,2
4
3
2 4 2,42 4 2 4,2
2
3 5 3,13 5 3 5,3
1
4 6 3,84 6 4 6,4
0
5 7 4,55 7 5 7,5 3 4 5 6 7 8 9
6 8 5,26 8 5 8,5
7 9 5,97 9 6 9,6
3. Brensenham
The steps in drawing a line using the Brensenham are as follows:
1. Determine the two points to be connected in the formation of the line
2. Determine the two points, starting point and endpoint (𝑥0 , 𝑦0 ) 𝑎𝑛𝑑 (𝑥1 , 𝑦1 )
3. Calculate 𝑑𝑥, 𝑑𝑦, 2|𝑑𝑥|𝑎𝑛𝑑 2|𝑑𝑦| − 2|𝑑𝑥|
𝑑𝑥 = 𝑥1 − 𝑥0 𝑎𝑛𝑑 𝑑𝑦 = 𝑦1 − 𝑦0
4. Calculate parameters: 𝑝𝑜 = 2|𝑑𝑦| − |𝑑𝑥|
5. For each 𝑥𝑘 along the line path, starting with k = 0
a. If 𝑝𝑘 < 0 then the next point is:
(𝑥𝑘 + 1, 𝑦𝑘 ) 𝑎𝑛𝑑 𝑝𝑘 + 1 = 𝑝𝑘 + 2|𝑑𝑦|
b. If not, the the next point is:
(𝑥𝑘 + 1, 𝑦𝑘 + 1) 𝑎𝑛𝑑 𝑝𝑘 + 1 = 𝑝𝑘 + 2|𝑑𝑦| − 2|𝑑𝑥|
6. Repeat number 5 to determine the next pixel position, until 𝑥 = 𝑥1 𝑎𝑛𝑑 𝑦 = 𝑦1
7. Finish
Settlement:
Diagonal Line (Brensenham)
Draw a horizontal line from (2, 1) to (9,6) using the Brensenham algorithm
1. Point A (2,1) and B (9,6)
2. Start point (𝑥0 − 𝑦0 ) = 𝐴(2,1) 𝑎𝑛𝑑 𝑒𝑛𝑑 𝑝𝑜𝑖𝑛𝑡 (𝑥1 − 𝑦1 ) = 𝐵(8,5)
3. Count
𝑑𝑥 𝑑𝑦 2|𝑑𝑥| 2|𝑑𝑦|
𝑑𝑥 = 𝑥1 − 𝑥0 𝑑𝑦 = 𝑦1 − 𝑦0 2|𝑑𝑥| = 2. 𝑑𝑥 2|𝑑𝑦| = 2. 𝑑𝑦
𝑑𝑥 = 9 − 2 𝑑𝑦 = 6 − 1 2|𝑑𝑥| = 2.7 2|𝑑𝑦| = 2.5
𝑑𝑥 = 7 𝑑𝑦 = 5 2|𝑑𝑥| = 14 2|𝑑𝑦| = 10
Calculate Line Slope:
𝑑𝑦
𝑚= 𝑑𝑥
5
𝑚= 7
𝑚 = 0,71
Line deviations 0 < m < 1
Iteration 𝑘 𝑝𝑘 𝑥𝑘 𝑦𝑘 (𝑥, 𝑦)
to
1 0 3 = 𝑥𝑘 + 1 = 𝑦𝑘 + 1 (3,2)
=2+1 = 1+1
=3 =2
2 1 = 𝑝𝑘 + 2|𝑑𝑦| − 2|𝑑𝑥| = 𝑥𝑘 + 1 = 𝑦𝑘 + 1 (4,3)
= 3 + 10 − 14 =3+1 = 2+1
= −1 =4 =3
3 2 = 𝑝𝑘 + 2|𝑑𝑦| = 𝑥𝑘 + 1 = 𝑦𝑘 (5,3)
= −1 + 10 =4+1 =3
=9 =5
4 3 = 𝑝𝑘 + 2|𝑑𝑦| − 2|𝑑𝑥| = 𝑥𝑘 + 1 = 𝑦𝑘 + 1 (6,4)
= 9 + 10 − 14 =5+1 = 3+1
=5 =6 =4
5 4 = 𝑝𝑘 + 2|𝑑𝑦| − 2|𝑑𝑥| = 𝑥𝑘 + 1 = 𝑦𝑘 + 1 (7,5)
= 5 + 10 − 14 =6+1 = 4+1
=1 =7 =5
6 5 = 𝑝𝑘 + 2|𝑑𝑦| − 2|𝑑𝑥| = 𝑥𝑘 + 1 = 𝑦𝑘 + 1 (8,6)
= 1 + 10 − 14 =7+1 = 5+1
= −3 =8 =6
7 6 = 𝑝𝑘 + 2|𝑑𝑦| = 𝑥𝑘 + 1 = 𝑦𝑘 (9,6)
= −3 + 10 =8+1 =6
=7 =9
Brensenham
x1 2 x2 9
y1 1 y2 6
dx 7 2dx 14
dy 5 2dy 10
m 0,714286 k 0
po 3
BRENSENHAM
7
Iteration k pk xk yk (x,y) 6
1 0 3 3 2 3,2 5
2 1 -1 4 3 4,3 4
3 2 9 5 3 5,3 3
4 3 5 6 4 6,4 2
5 4 1 7 5 7,5 1
6 5 -3 8 6 8,6 0
3 4 5 6 7 8 9
7 6 7 9 6 9,6
D. CONCLUSION
In computer graphics, there are three commonly used algorithms for drawing objects: the
Brute Force Algorithm, the Digital Differential Analyzer (DDA) Algorithm, and the
Bresenham Algorithm. The Brute Force Algorithm, while simple and flexible, is often
less efficient, especially for large and complex objects, and it may result in inaccuracies
for objects with sharp angles. On the other hand, the DDA Algorithm provides an
efficient solution for drawing straight lines with good accuracy, although it is limited to
straight lines. Among these three, the Bresenham Algorithm stands out as a highly
efficient and accurate choice for drawing straight lines in computer graphics applications.
However, it's worth noting that some modifications may be needed to optimally draw
vertical or horizontal lines.