Bresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
Y = m (Xk + 1 ) + c -------
● Xnext = Xk + 1
● Ynext = Yk + 1 (OR) Yk
● Y = m (Xk + 1 ) + c ---- will be floating value but we
need an integer value
Let’s start the derivation
● So how to get rid of it. We can get rid of the denominator �x altogether
● If Pnext - Pk < 0, then remain on the same size for Ynext that is Yk
○ Pnext = Pk + 2�y
● If Pk+1 - Pk < 0, then remain on the same size for Ynext that is Yk
○ Pk+1 = Pk + 2�y
● P1 = 2�y - �x
Algo_Bresenham(x1, y1, x2, y2)
{
dx = x2 – x1
dy = y2 – y1
P = 2dy - dx
for(i = 0 to dx)
{
put_pixel ( x, y )
x++
Bresenham Algo If (P < 0)
{
P = P + 2dy
}
else
{
P = P + 2dy - 2dx
y++
}
}
}
Examples for Practice