0% found this document useful (0 votes)
70 views4 pages

Chapter 2

The document summarizes two common algorithms for drawing lines in computer graphics - the Digital Differential Analyzer (DDA) algorithm and Bresenham's line algorithm. The DDA algorithm calculates intermediate points along the line by determining the change in x and y between endpoints and incrementing by those amounts. Bresenham's algorithm uses integer arithmetic to determine the next point, incrementing the x or y value based on a decision parameter to favor one axis over the other. Both algorithms are described with examples to illustrate their application for drawing lines between two points.

Uploaded by

avinash badal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views4 pages

Chapter 2

The document summarizes two common algorithms for drawing lines in computer graphics - the Digital Differential Analyzer (DDA) algorithm and Bresenham's line algorithm. The DDA algorithm calculates intermediate points along the line by determining the change in x and y between endpoints and incrementing by those amounts. Bresenham's algorithm uses integer arithmetic to determine the next point, incrementing the x or y value based on a decision parameter to favor one axis over the other. Both algorithms are described with examples to illustrate their application for drawing lines between two points.

Uploaded by

avinash badal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CHAPTER 2

Graphics Primitives

POINT and LINE

POINT

 Point plotting is accomplished by converting a single coordinate position furnished by an application program into appropriate operations for the output
device.
 A Random-Scan (Vector) System stores point-plotting instructions in the display list, and coordinate values in these instructions are converted to
deflection voltages that position the electron beam at the screen locations to be plotted during each refresh cycle.
 For a black-and-white raster system, a point is plotted by setting the bit value corresponding to a specified screen position within the frame buffer to 1.
Then, as the electron beam sweeps across each horizontal scan line, it emits a burst of electrons (plots a point) whenever a value of 1 is encountered in
the frame buffer.

LINE

 Line drawing is accomplished by calculating intermediate positions along the line path between two specified endpoint positions. An output device
is then directed to fill in these positions between the endpoints.
 For a raster video display, the line color (intensity) is then loaded into the frame buffer at the corresponding pixel coordinates. Reading from the
frame buffer, the video controller then "plots" the screen pixels. Screen locations are referenced with integer values, so plotted positions may only
approximate actual Line positions between two specified endpoints.

Line Drawing Algorithm

1. DDA Algorithm:- In any 2-Dimensional plane if we connect two points (x0, y0) and (x1, y1), we get a line segment. But in the case of computer
graphics we can not directly join any two coordinate points, for that we should calculate intermediate point’s coordinate and put a pixel for each
intermediate point, of the desired color with help of functions like putpixel(x, y, K) in C, where (x,y) is our co-ordinate and K denotes some color.

Procedure-
 
Given-
 Starting coordinates = (X0, Y0)
 Ending coordinates = (Xn, Yn)
 
The points generation using DDA Algorithm involves the following steps-
 
Step-01:
 
Calculate ΔX, ΔY and M from the given input.
These parameters are calculated as-
 ΔX = Xn – X0
 ΔY =Yn – Y0
 M = ΔY / ΔX
 
Step-02:
 
Find the number of steps or points in between the starting and ending coordinates.
 
if (absolute (ΔX) > absolute (ΔY))
Steps = absolute (ΔX);
else
Steps = absolute (ΔY);
 
Step-03:
 
Suppose the current point is (Xp, Yp) and the next point is (Xp+1, Yp+1).
Find the next point by following the below three cases-
 

 
Step-04:
 
Keep repeating Step-03 until the end point is reached or the number of generated new points (including the starting and ending points) equals to the
steps count.
 

PRACTICE PROBLEMS BASED ON DDA ALGORITHM-


 
Problem-01:
 
Calculate the points between the starting point (5, 6) and ending point (8, 12).
 
Solution-
 
Given-
 Starting coordinates = (X0, Y0) = (5, 6)
 Ending coordinates = (Xn, Yn) = (8, 12)
 
Step-01:
 
Calculate ΔX, ΔY and M from the given input.
 ΔX = Xn – X0 = 8 – 5 = 3
 ΔY =Yn – Y0 = 12 – 6 = 6
 M = ΔY / ΔX = 6 / 3 = 2
 
Step-02:
 
Calculate the number of steps.
As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6
 
Step-03:
 
As M > 1, so case-03 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.
 
Round off
Xp Yp Xp+1 Yp+1
(Xp+1, Yp+1)

5 6 5.5 7 (6, 7)

6 8 (6, 8)

6.5 9 (7, 9)

7 10 (7, 10)

7.5 11 (8, 11)

8 12 (8, 12)
 
Advantages of DDA Algorithm-
 
The advantages of DDA Algorithm are-
 It is a simple algorithm.
 It is easy to implement.
 It avoids using the multiplication operation which is costly in terms of time complexity.
 
Disadvantages of DDA Algorithm-
 
The disadvantages of DDA Algorithm are-
 There is an extra overhead of using round off( ) function.
 Using round off( ) function increases time complexity of the algorithm.
 Resulted lines are not smooth because of round off( ) function.
 The points generated by this algorithm are not accurate.

2. Bresenham’s line Algorithm

Procedure-
 
Given-
 Starting coordinates = (X0, Y0)
 Ending coordinates = (Xn, Yn)
 
The points generation using Bresenham Line Drawing Algorithm involves the following steps-
 
Step-01:
 
Calculate ΔX and ΔY from the given input.
These parameters are calculated as-
 ΔX = Xn – X0
 ΔY =Yn – Y0
 
Step-02:
 
Calculate the decision parameter Pk.
It is calculated as-
Pk = 2ΔY – ΔX
 
Step-03:
 
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1). Find the next point depending on the value of decision parameter P k.
Follow the below two cases-
 

 
Step-04:
 
Keep repeating Step-03 until the end point is reached or number of iterations equals to (ΔX-1) times.
 

PRACTICE PROBLEMS BASED ON BRESENHAM LINE DRAWING ALGORITHM-


 
Problem-01:
 
Calculate the points between the starting coordinates (9, 18) and ending coordinates (14, 22).
 
Solution-
 
Given-
 Starting coordinates = (X0, Y0) = (9, 18)
 Ending coordinates = (Xn, Yn) = (14, 22)
 
Step-01:
 
Calculate ΔX and ΔY from the given input.
 ΔX = Xn – X0 = 14 – 9 = 5
 ΔY =Yn – Y0 = 22 – 18 = 4
 
Step-02:
 
Calculate the decision parameter.
Pk
= 2ΔY – ΔX
=2x4–5
=3
So, decision parameter Pk = 3
 
Step-03:
 
As Pk >= 0, so case-02 is satisfied.
 
Thus,
 Pk+1 = Pk + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
 Xk+1 = Xk + 1 = 9 + 1 = 10
 Yk+1 = Yk + 1 = 18 + 1 = 19
 
Similarly, Step-03 is executed until the end point is reached or number of iterations equals to 4 times.
(Number of iterations = ΔX – 1 = 5 – 1 = 4)
 
P
Pk+1 Xk+1 Yk+1
k

9 18

3 1 10 19

1 -1 11 20

- 7 12 20
1

7 5 13 21

5 3 14 22
 

You might also like