Transcript
Page 1: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

Line Drawing Algorithms

Page 2: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

• Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen.

• Scan Conversion-Digitizing a picture definition given in an application program into a set of pixel intensity values for storage in the frame buffer.

Page 3: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

Output primitives -Basic geometric structures.

A scene is described in such a way that the graphics programming packages provide functions to describe a scene in terms of basic geometric structures called output primitives and to group sets of o/p primitives into more complex structures

Each output primitive is specified with the input coordinate data and other information about the way that object is to be displayed.

Page 4: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

Points- Point plotting is accomplished by converting a single coordinate position in an application program into appropriate operations for the output device in use.

Line- Line drawing is accomplished by calculating intermediate positions along the line path between 2 specified end point positions. The output device is directed to fill these positions between the end points.

Page 5: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

0 1 2 3 4

0

1

2

3

4

Scan Line number

Pixel Column number

Page 6: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing
Page 7: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing
Page 8: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing
Page 9: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing
Page 10: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

x1 x2

y1

y2

Straight line segment with 5 sampling positions along the x axis and y axis

Page 11: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

• The Cartesian slope intercept eqn for straight line is y = m x + b

• (x1,y1) & (x2,y2) be the two endpoints of the line, then m=(y2-y1)/(x2-x1)

b= y1- mx1

i.e y1 = mx1 + b

y2 = mx2 + b(3) –(2)

( y2-y1) = m (x2 – x1)

m=(y2-y1)/(x2-x1) ie ∆y/ ∆x

(2)

(3)

(1)

Page 12: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

• For any given x interval ∆x along a line, compute the corresponding y interval ∆y as ∆y = m ∆x

• Similarly the x interval is obtained as

∆x = ∆y /m

The above eqns form the basis for determining deflection voltages.

Page 13: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

Lines with slope magnitude |m| <1, ∆x is set proportional to a small horizontal deflection voltage and the corresponding vertical deflection voltage ∆y is ∆y = m ∆x

∆x> ∆y

Lines with slope magnitude |m| >1, ∆y is set proportional to a small vertical deflection voltage and the corresponding horizontal deflection voltage is ∆x = ∆y /m

∆y> ∆x

P1

P2

P1

P2

Page 14: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

Digital Differential Algorithm(DDA)• Scan conversion algorithm based on

calculating either ∆x or ∆y.• Sample the line at unit intervals in one

coordinate and determine the corresponding integer values nearest the line path for the other coordinate.

Case 1

Line with positive slope less than or equal to 1, we sample at unit x intervals (∆x =1) and determine the successive y value as

Yk+1= Yk + m ∆y=m ∆x Yk+1- Yk =m ∆x Yk+1- Yk =m (∆x =1)

Page 15: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

• k takes integer values starting from 1 and increases by 1 until the final point is reached.

• m can be any number between 0 and 1.• Calculated y values must be rounded off to

the nearest integer.• For lines with positive slope greater than 1,

sample at unit y intervals (∆y = 1) and calculate each successive x value as

xk+1= xk + 1/m

The above eqns are based on the assumption that lines are processed from left to right. If the processing is reversed then

∆x = -1 & yk+1 = yk – mSlope <1∆y = -1 & xk+1= xk-1/m

Slope >1

Page 16: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

StepsP1 ( xa,ya) and P2 (xb,yb) are the two end points.

2. Horizontal and vertical differences between the endpoint positions are computed & assigned to two parameters namely dx and dy.

3. The difference with greater magnitude determines the ‘value’ of increments to be done. That means the number of times sampling has to be done. This value is assigned to a parameter called ‘steps’.

Page 17: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

4. Starting from the 1st pixel ,we determine the offset needed at each step to generate the next pixel position along the line path. Call the offset value as xincrement and yincrement.The starting points are xa and ya.

Assign x =xa and y=ya

x= x+ xincr & y= y+ yincr

5. Loop through the process steps times, till the last point xb, yb is reached.

P1 (xa,ya)

P2 (xb,yb)

Page 18: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

Step 1: Accept as input the 2 end point pixel position. P1(xa,ya) P2 (xb, yb)

Step 2: Horizontal and vertical differences between the endpoint positions are computed & assigned to two parameters namely dx and dy.

dx= xb – xa dy = yb - ya

Steps for DDA Algorithm

Page 19: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

• Step 3: If abs(dx) >abs(dy) steps =abs( dx)

else steps =abs( dy)• Step 4: xincr = dx/steps (if steps = abs(dx) , xincr = 1)

yincr =dy/steps(ie dy/dx = m)

Assign x= xa and y=ya x= x+ xincr & y= y+ yincr

• Step 5: Loop through the process steps times.

Page 20: Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing

Advantages

DDA algorithm is a faster method for calculating the pixel positions than the direct use of line equation.

• It eliminates multiplication by making use of raster characteristics.

Disadvantages

• DDA algorithm runs slowly because it requires real arithmetic (floating point operations) and rounding operations.


Recommended