Chapter 2
Chapter 2
Graphics Primitives
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.
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.
5 6 5.5 7 (6, 7)
6 8 (6, 8)
6.5 9 (7, 9)
7 10 (7, 10)
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.
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.
9 18
3 1 10 19
1 -1 11 20
- 7 12 20
1
7 5 13 21
5 3 14 22