Sunteți pe pagina 1din 5

What are Output Primitives?

 Functions which describe a scene in terms


Chapter 3 of basic geometric structures are referred
Output Primitives to as output primitives.
Each output primitive is specified with the input
Line drawing algorithms 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? How do computers draw lines?

 It is the responsibility of the graphics  Calculate intermediate steps between two


system to convert each primitive from its specified end-points [(x1,y1) & (x2,y2)].
geometric description into a set of pixels
 Frame buffer is loaded with pixel
that make up the primitive in the image
coordinates & intensities.
space.
 Display device is then directed to fill these
 This process is known as scan conversion
positions.
or rasterization.
 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 Basic line drawing algorithm

 Rounding off coordinate values to integers Equation of straight


cause the line to be displayed in a stair- line is:
step fashion (‘jaggies’).
y = m.x + b y2

Given two end-points


Particularly noticeable [(x1,y1) & (x2,y2)]
on systems with y1
m = (y2 – y1)/(x2 – x1)
low resolution x1 x2
b = y1 – m. x1

Slope of a line

Line drawing (contd …) Line drawing (contd …)

If |m| <= 1 Increment x by 1 If |m| = 1


For every integer value of x between Can use any of the above schemes.
and excluding x1 & x2, calculate the The output line will be smooth.
corresponding value of y by: y = m.x + b What about horizontal & vertical
If |m| > 1 Increment y by 1
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) How the algorithm works?

 m = (5 – 1)/(6 – 1) |m| <= 1


= 4/5
Using y = m.x + b
= 0.8
x = 2, y = 1.8 ≈ 2
 b = 1 – (0.8)(1)
x = 3, y = 2.6 ≈ 3 6
5
= 1 – 0.8 4

= 0.2
x = 4, y = 3.4 ≈ 3 3
2
1
x = 5, y = 4.2 ≈ 4 1 2 3 4 5 6

Try the following … Problems

1. (x1=1,y1=6)&(x2=6,y2=1)  What about the case, when m = ∞


2. (x1=1,y1=1)&(x2=5,y2=8)  How to solve this problem?
3. (x1=2,y1=1)&(x2=2,y2=6)  Floating point computations (multiplication
& addition).
4. (x1=1,y1=4)&(x2=6,y2=4)

3
DDA algorithm DDA algorithm (contd…)

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

DDA (|m| <= 1) DDA (|m| > 1)


 Start with x = x1 & y = y1. Assuming x1 < x2  Start with x = x1 & y = y1. Assuming y1 < y2
. .
 Set ∆x = 1 (unit increment in x-direction).  Set ∆y = 1 (unit increment in y-direction).
 y-coordinate is calculated using equation  x-coordinate is calculated using equation
(3). (4 ).
 
 
 
 Process continues till x reaches x2.  Process continues till y reaches y2.

4
Advantages & disadvantages of DDA

 Faster than the direct use of the line


equation and it does not do any floating
point multiplication.
 Floating point Addition is still needed.
 Precision loss because of rounding off.
Pixels drift farther apart if line is relatively
larger.

S-ar putea să vă placă și