# Scan Conversion A. Samal. Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles.

## Presentation on theme: "Scan Conversion A. Samal. Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles."— Presentation transcript:

Scan Conversion A. Samal

Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles Hardware implementations preferable

Lines Compute the coordinate of the pixels that lie on a line on a 2D raster Defined by the coordinates of the end points Criteria – Thin – As close to ideal as possible – 1 pixel wide If -1<= slope <= 1 exactly 1 pixel in one column Else exactly 1 pixel in one row – Constant brightness, independent of the length & orientation – Should be drawn fast

Scan Conversion of Lines

Basic Incremental Algorithm

Problem for each x plot pixel at closest y – Problems for steep lines

Basic Incremental Algorithm Desired Line

Basic Incremental Algorithm Brute force algorithm Inefficient Each iteration – Floating point multiply – Floating point addition – Rounding

Basic Incremental Algorithm Eliminate the multiplication Incremental computation Digital Differential Analyzer (DDA)

Basic Incremental Algorithm If the magnitude of the slope is more than 1 change the role of x and y in the algorithm – y increases faster than x Simple but inefficient – Still there are floating point operations Bresenham’s algorithm – Uses only integer arithmetic – Avoids round function – Extended to drawing circles

Midpoint Line Algorithm E NE M Previous Pixel Current Pixel Choices Next Pixel Choices

Midpoint Line Algorithm Compute the distance between – Q and E – Q and NE See which side of the line M lies M lies below the line – Choose NE M lies above the line – Choose E M lies on the line – Choose either E NE M Previous Pixel Current Pixel Choices Next Pixel Choices

Midpoint Line Algorithm

E NE M Previous Pixel Current Pixel Choices Next Pixel Choices

Midpoint Line Algorithm What happens at the next grid point? – Depends on whether we choose N or NE If E is chosen E NENE M Previo us Pixel Current Pixel Choices Next Pixel Choices

Midpoint Line Algorithm If NE is chosen E NENE M Previo us Pixel Current Pixel Choices Next Pixel Choices

Midpoint Line Algorithm Summary – Choose between the two pixels (E/NE) based on the sign of the decision variable d=F(M) – Update the decision variable by adding the change along that direction – Repeat this process until the end point is reached

Midpoint Line Algorithm

Fractional arithmetic still problematic Should be avoided if possible Redefine F(x,y) by multiplying by 2 Thus F(x,y) = 2(ax+by+c) Replace all constants and the decision variable by 2 Removes all multiplications; only additions left

Midpoint Line Algorithm

MidpointLine(x0,y0,x1,y1,color) { int dx,dy,dE,dNE,d,x,y; dx=x1-x0; dy=y1-y0; d=2*dy-dx; dE=2*dy; dNE=2*(dy-dx); x=x0;y=y0; DrawPixel(x,y,color); for(x=x0;x { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/11/3248916/slides/slide_22.jpg", "name": "MidpointLine(x0,y0,x1,y1,color) { int dx,dy,dE,dNE,d,x,y; dx=x1-x0; dy=y1-y0; d=2*dy-dx; dE=2*dy; dNE=2*(dy-dx); x=x0;y=y0; DrawPixel(x,y,color); for(x=x0;x

Bresenham’s Algorithm An example 456789 7 8 9 10 11 12

Bresenham’s Algorithm An example 456789 7 8 9 10 11 12

Bresenham’s Algorithm An example 456789 7 8 9 10 11 12

Download ppt "Scan Conversion A. Samal. Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles."

Similar presentations