Lecture 5 - Plotting Points and Lines
Lecture 5 - Plotting Points and Lines
• What is an algorithm?
Plotting points and lines
• Plotting points
Illuminate a phosphor dot on a CRT
• Plotting lines
i. Specify the endpoint coordinates of each
line segment
ii. Fill the straight line path between the
end-points
• Line drawing is accomplished by calculating
intermediate positions along the line path between
two specified end point positions.
• An output device is then directed to fill in these
positions between the end points
• Discrete coordinate positions along the line path are
calculated from the equation of the line.
Line /Circle drawing Drawing
Algorithms
Step 2: Horizontal and vertical differences between the endpoint positions are
assigned to parameters dx and dy (Calculated dx= xb - xa and dy = yb - ya).
Step 3: The difference with the greater magnitude determines the value of
parameter steps.
Step 4 : Starting with pixel position (xa, ya), determine the offset (m) needed at
each step to generate the next pixel position along the line path.
Advantages of DDA
• 1. It is the simplest algorithm
• 2. It is a is a faster method for calculating pixel
positions
Disadvantages of DDA Algorithm
• 1. Floating point arithmetic in DDA algorithm is
still time-consuming
• 2. End point accuracy is poor
Practice Question
Start position
16
Bresenham Line Drawing
To illustrate the algorithm, we digitize the line with endpoints (20, 10) and (30, 18).
This line has a slope of 0.8, with
∆x = 10, ∆ y =8
We plot the initial point (x0, y0) = (20, 10), and determine successive pixel positions
along the line path from the decision parameter as:
Bresenham Line Drawing
Practice Question
21
Circle Algorithms
(-y, x) (y, x)
45°
p1 p3
yi
D(si)
yi - 1 D(ti)
p2
xi xi + 1
After point p1, do we choose p2 or p3?
x0 = 0
y0 = r
p0 = 3 – 2r
if pi < 0 then
yi+1 = yi
pi+1 = pi + 4xi + 6
xi+1 = xi + 1
else if pi ≥ 0 then
yi+1 = yi – 1
pi+1 = pi + 4(xi – yi) + 10
i pi xi, yi 9
0 -17 (0, 10) 8
7
1 -11 (1, 10)
6
2 -1 (2, 10)
5
3 13 (3, 10) 4
4 -5 (4, 9) 3
5 17 (5, 9) 2
1
7
0
0 1 2 3 4 5 6 7 8 9 10
25
• Draw the circle with r = 12 using the
Bresenham algorithm.
26