# What are Output Primitives?

Chapter 3 Output Primitives
Line drawing algorithms

Functions which describe a scene in terms of basic geometric structures are referred to as output primitives.
Each output primitive is specified with the input coordinate data & the way the primitive is to be displayed

Some output primitives include:
Points, line segments, circles, conic sections, spline curves, etc.

What is scan conversion?
It is the responsibility of the graphics system to convert each primitive from its geometric description into a set of pixels that make up the primitive in the image space. This process is known as scan conversion or rasterization.

How do computers draw lines?
Calculate intermediate steps between two specified end-points [(x1,y1) & (x2,y2)]. Frame buffer is loaded with pixel coordinates & intensities. Display device is then directed to fill these positions. Screen locations can only be integers, so floating point values are rounded off, e.g. (16.99,2.01) (17,2)

1

Problem with approximation
Rounding off coordinate values to integers cause the line to be displayed in a stairstep fashion (‘jaggies’).

Basic line drawing algorithm
Equation of straight line is:
y = m.x + b
y2

Particularly noticeable on systems with low resolution

Given two end-points [(x1,y1) & (x2,y2)]
m = (y2 – y1)/(x2 – x1) b = y1 – m. x1

y1 x1 x2

Slope of a line

Line drawing (contd …)
If |m| <= 1
Increment x by 1

Line drawing (contd …)
If |m| = 1
Can use any of the above schemes. The output line will be smooth.

For every integer value of x between and excluding x1 & x2, calculate the corresponding value of y by: y = m.x + b

If |m| > 1

Increment y by 1

What about horizontal & vertical lines?

For every integer value of y between and excluding y1 & y2, calculate the corresponding value of x by: x = (y – b)/m

2

Example: (x1=1,y1=1)&(x2=6,y2=5)
m = (5 – 1)/(6 – 1) = 4/5 = 0.8 b = 1 – (0.8)(1) = 1 – 0.8 = 0.2

How the algorithm works?
|m| <= 1 Using y = m.x + b x = 2, y = 1.8 ≈ 2 x = 3, y = 2.6 ≈ 3 x = 4, y = 3.4 ≈ 3 x = 5, y = 4.2 ≈ 4

6 5 4 3 2 1 1 2 3 4 5 6

Try the following …

Problems
What about the case, when m = ∞ How to solve this problem? Floating point computations (multiplication & addition).

1. 2. 3. 4.

(x1=1,y1=6)&(x2=6,y2=1) (x1=1,y1=1)&(x2=5,y2=8) (x1=2,y1=1)&(x2=2,y2=6) (x1=1,y1=4)&(x2=6,y2=4)

3

DDA algorithm
Digital Differential Analyzer. Incremental line generating algorithm. Concept: perform calculations at each step, using the results of the previous steps. At step i: (xi,yi). At step i+1: (xi+1,yi+1), use m = y/ x. y = yi+1 – yi _______ (1) x = xi+1 – xi _______ (2)

DDA algorithm (contd…)
Substituting (1) & (2) in m = y/ x, we get: yi+1 = yi + m. x x=1 yi+1 = yi + m _______ (3) xi+1 = xi + y/m y=1 xi+1 = xi + 1/m _______ (4)

DDA (|m| <= 1)
Start with x = x1 & y = y1. Assuming x1 < x2 . Set x = 1 (unit increment in x-direction). y-coordinate is calculated using equation (3).

DDA (|m| > 1)
Start with x = x1 & y = y1. Assuming y1 < y2 . Set y = 1 (unit increment in y-direction). x-coordinate is calculated using equation (4 ).

Process continues till x reaches x2.

Process continues till y reaches y2.

4