Sunteți pe pagina 1din 20

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.

Scan Line number

1
0

Pixel Column number

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

y2

y1

x1

x2

The Cartesian slope intercept eqn for (1) 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 (2) i.e y1 = mx1 + b (3) y2 = mx2 + b
(3) (2)

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

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.

Lineswithslopemagnitude|m|<1,xisset proportional to a small horizontal deflection voltage and the corresponding vertical deflectionvoltageyisy=m x
P2

x>y

P1

Lineswithslopemagnitude|m|>1,y is set proportional to a small vertical deflection voltage and the corresponding horizontal deflection voltage is x=y/m P2 y>x

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=mx Yk+1- Yk=mx 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 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 & y=-1 & yk+1 = yk m xk+1= xk-1/m
Slope >1

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

Steps for DDA Algorithm

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

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.

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.

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