7814 Et ET
7814 Et ET
e-PG Pathshala
Subject : Computer Science
Paper: Computer Graphics and Visualization
Module: Bresenham’s Line drawing procedure
Module No: CS/CGV/3
Quadrant 1 – e-text
Learning Objectives:
Let’s start our assumptions with a line whose slope <1 i.e. the line is more
inclined towards x-axis, so it is obvious to sample the line along x-axis at unit x-
intervals and compute the corresponding y values. Also that to compute next points
on a line, we always starts with a known point on the line and tries computing the
next unknown point on the line using recursive equations.
So the next x i.e. xk+1=xk+1 and the next y i.e. yk+1 is to be computed. Let the
known plotted point on the line be (xk,yk).
Before we get into the derivation lets understand the underlying principle of
Bresenham’s procedure. To compute the next point on the line (Xk+1, Yk+1), a value
called ‘decision parameter’ is computed. Based on the result a pixel is chosen for
plotting.
As shown in the figure above let the line shown be the theoretical line and we
need to find the best possible approximation for this by computing Bresenham’s line.
For the next X position, Xk+1, the corresponding Y value could not be plotted as the
position (Xk+1, y) does not exist on the monitor. We have to choose between Yk and
Yk+1. i.e. next position to be plotted is either (Xk+1, Yk) or (Xk+1, Yk+1). Now how do
we decide among the two choices. The answer is, compute the vertical difference
between the possible pixel position and the position on the true theoretical line which
is.
Let dlower be the vertical difference between the position (y) on theoretical line and
the lower pixel (yk) and dupper be the vertical difference between the position (y) on
theoretical line and the upper pixel (yk+1). As evident if dlower is < dupper the theoretical
line is closer to the lower pixel so choose position (Xk+1, Yk) otherwise choose
position. The difference between dlower and dupper is considered as ‘decision
parameter’, as the sign of the difference operation helps us decide what y coordinate
position is to be chosen for the next x.
‘Decision parameter’ referred to as pk helps us decide which of the pixels is to
be chosen
Whichever pixel position is close to the theoretical line, that pixel is chosen.
i.e. next X is Xk+1 = Xk+1, and next Y is Yk+1=Yk or Yk+1 depending on the sign of pk.
In the above step it is interesting to observer that division due to dy/dx is avoided by
cross multiplying dy/dx with the equations
Where pk is Δx(dlower-dupper). And we know that Xk+1 = Xk+1. The above equation
reduces to
Because Δx(2C-1) is a constant with Δx and C being constants for a given line with
end points we can replace Δx(2C-1) with a constant say ‘b’.
Let Pk+1 be the next decision parameter. We do this to find a recursive relation
between Pk and Pk+1. i.e. wherever there is k replace that with k+1 in the previous
equation to obtain Pk+1
Case(i):
If pk <=0 the lower pixel (Xk+1,Yk ) is to be plotted, i.e. next x is Xk+1 and next y is Yk.
Therefore yk+1=yk. Now the previous equation for Pk+1 reduces to
Case(ii):
If pk >0 the upper pixel (Xk+1,Yk+1) is to be plotted, Therefore next y, yk+1=yk+1 ,
now substituting for yk+1 in the equation for Pk+1 we get
The initial decision parameter p0 is computed as below (use the following eq.)
All this is well only for lines with slopes <1. What about other line types?
Now let’s summarize the equations as below,
When |m|<=1
and
Case (ii): If pk>0 the upper pixel (Xk+1,Yk+1) is to be plotted
and
When |m|>1
and
Compute absolute values of ∆x, ∆y
Summary: