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

## Presentation on theme: "Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing."— Presentation transcript:

Line Drawing Algorithms

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.

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.

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.

01 2 34 0 1 2 3 4 Scan Line number Pixel Column number

x1 x2 y1 y2 Straight line segment with 5 sampling positions along the x axis and y axis

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)‏

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.

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

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 Y k+1 = Yk + m ∆y=m ∆x Yk+1- Yk =m ∆x Yk+1- Yk =m (∆x =1)‏

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 x k+1 = x k + 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 & y k+1 = y k – m Slope <1 ∆y = -1 & x k+1 = x k -1/m Slope >1

Steps P1 ( 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’.

4. Starting from the 1 st pixel,we determine the offset needed at each step to generate the next pixel position along the line path. Call the offset value as x increment and y increment. The starting points are xa and ya. Assign x =xa and y=ya x= x+ x incr & y= y+ y incr 5. Loop through the process steps times, till the last point xb, yb is reached. P1 (xa,ya)‏ P2 (xb,yb)‏

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 – xady = yb - ya Steps for DDA Algorithm

Step 3: If abs(dx) >abs(dy) steps =abs( dx)‏ else steps =abs( dy)‏ Step 4: x incr = dx/steps (if steps = abs(dx), xincr = 1)‏ y incr =dy/steps (ie dy/dx = m)‏ Assign x= xa and y=ya x= x+ x incr & y= y+ y incr Step 5: Loop through the process steps times.

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.

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

Similar presentations