Algorithm
Algorithm
• Once pixel positions have been identified the color values must be
stored in the frame buffer
• Assume we have available a low-level procedure of the form
DDA
Bresenham’s Midpoint
Algorithm
Algorithms for displaying lines are based on the Cartesian
slope-intercept equation
y = m.x + b
where m and b can be calculated from the line endpoints:
m = (y1-y0) / (x1-x0)
b = y0 - m. x0
y1
y0
x0 x1
Simple Line
Based on slope-intercept
algorithm from algebra:
y = mx + b
Simple approach:
increment x, solve for y
Floating point arithmetic
required
Does it Work?
• Decide what is
the next pixel
13 Specified position
line path
– (11,11) or
12
(11,12)
11
10
10 11 12 13
Illustrating Bresenham’s Approach
yk+1
yk
• y=m(xk + 1)+b
yk+1
dupper
y
• dlower=y-yk
dlower =m(xk + 1)+b-yk
yk
• dupper=(yk+1)-y
xk+1 = yk+1 -m(xk + 1)-b
• dlower- dupper= 2m(xk + 1)+2yk+2b-1
• Rearrange it to have integer calculations:
m=Δy/Δx
Decision parameter: pk= Δx(dlower- dupper)=2Δy.xk - 2Δx. yk + c