This preview shows pages 1–8. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition of line drawing Given two points P and Q in the plane, both with integer coordinates, determine which pixels on a raster screen should be on in order to make a picture of a unitwidth line segment starting from P and ending at Q. 0 1 2 3 4 5 6 6 5 4 3 2 1 (3, 3) Line drawing (cont) The thinnest line is of onepixel wide. We will concentrate on drawing a line of 1 pixel resolution. The Cartesian slopeintercept equation for a straight line is y= m. x + b m is the slope of the line and b is the y intercept. Given the endpoints of a line segment. m = y2y1 / x2x1 b= y1m.x1 Line Drawing (cont) Also for any given interval x along a line, we can compute the corresponding y interval y from y= m. x Similarly we can obtain the x interval x corresponding to a specified y as x= y / m These equations form the basis for determining deflection voltages in analog devices. Line Drawing (cont) Also , for any given x interval x along a line, we can compute the corresponding y interval y from y= m. x These equations form the basis for determining deflection voltages in analog devices. On Raster systems, lines are plotted with pixels, and step sizes in the horizontal and vertical directions are constrained by pixel separations. Hence we ought to sample a line at discrete positions and determine the nearest pixel to the line at each sampled position. Symmetry If we could draw lines with positive slope (0<=slope<=1) we would be done. For a line with negative slope (0>=slope>=1) We negate all Y values For a line with slope > 1 or slope <1 we just swap x and y axes 45 (y,x) (x,y) (x,y) (y,x) (y,x) (x,y) (x,y) (y,x) Code for drawing a line Invert_y_draw ( int x,int y ) draw_pixel(x,y) Swap_xy_draw ( int x,int y )...
View
Full
Document
This note was uploaded on 04/05/2010 for the course COMPUTER S 876 taught by Professor Ch during the Spring '10 term at Amirkabir University of Technology.
 Spring '10
 ch

Click to edit the document details