Professional Documents
Culture Documents
(dlower – dupper )
Bresenham's Line Algorithm
• The y coordinate on the line is calculated by: y = m(xk + 1) + b
and
• dlower = y – yk
• dupper = yk+1 – y
– dupper = 2m(xk + 1) – 2yk + 2b –
dlower
• Since 1m is < 1 (recall it's in the 1st octant) it is a non-integer. That's not good so,
• replace it with dy/dx, where dy is the change in y endpoints and dx is the change in
x endpoints – these will be integer values divided --- but we'll get rid of the division.
• – dupper = 2 ( dy / dx )(xk + 1) – 2yk + 2b –
dlower
1 both sides by dx and get:
• Multiply
• – dupper ) = 2 dy (xk + 1) – 2 dx yk + 2 dx b –
dx (dlower
• dx
• 2
dxdy – bdupper
+ 2 dx
(dlower – dx) = is
2 a constant
dy xk –which
2 dx yisk + 2 dy + 2 dxofb each
independent – iteration
dx
Bresenham's Line Algorithm
• So we end up with
• – dupper ) = 2 dy xk – 2 dx yk + c
dx (dlower
• We only need to determine the sign of
– dupper )
(d
dxlower
is positive so it doesn't have an effect on the sign (so now there's no need to
• divide) --- does that make sense?
• Letpk = dx (dlower is the decision parameter
– dupper )
pk
• So, we check if 2 dy xk – 2 dx yk + c < 0 and if it is we turn on the lower pixel,
so