Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.

Slides:



Advertisements
Similar presentations
Circle Drawing Asst. Prof. Dr. Ahmet Sayar Kocaeli University
Advertisements

Line Drawing Algorithms
Graphics Primitives: line
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Drawing Elementary Figures Dr. Eng. Farag Elnagahy.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Scan conversion of Line , circle & ellipse
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 50 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 45 Computer Graphics Implementation I.
University of Missouri at Columbia 2D Scan-line Conversion University of Missouri at Columbia.
Course Website: Computer Graphics 5: Line Drawing Algorithms.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
Rasterization Foley, Ch: 3. Pixels are represented as disjoint circles centered on uniform grid Each (x,y) of the grid has a pixel Y X (1,1) (1,2) (0,0)
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
Graphics Primitives: line. Pixel Position
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
3/4/04© University of Wisconsin, CS559 Spring 2004 Last Time Clipping Lines –Cohen-Sutherland: The use of outcodes and early reject/accept tests –Liang-Barsky:
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
2 pt 3 pt 4 pt 5pt 1 pt 2 pt 3 pt 4 pt 5 pt 1 pt 2pt 3 pt 4pt 5 pt 1pt 2pt 3 pt 4 pt 5 pt 1 pt 2 pt 3 pt 4pt 5 pt 1pt Slope-Intercept Form Point-Slope.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
1 Circle Drawing Algorithms Pictures snagged from
Graphics Graphics & Graphical Programming Lecture 14 - Lines & Circles.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
Computer Graphics Drawing Line. Lines and Polylines Convex: For every pair of points in the polygon, the line between them is fully contained in the polygon.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Scan Conversion.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
Computer Graphics : output primitives.. 2 of 32 T1 – pp. 103–123, 137–145, 147–150, 164–171 Points and LinesPoints Line Drawing AlgorithmsLine Mid–Point.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Line Drawing Algorithms 1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction. 2. It is defined.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Scan Conversion or Rasterization
Computer Graphics Drawing Line.
CSCE 441 Lecture 2: Scan Conversion of Lines
(c) 2002 University of Wisconsin, CS559
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
Computer Graphics Implementation I.
Scan Conversion of Lines
CSCE 441 Lecture 2: Scan Conversion of Lines
© University of Wisconsin, CS559 Fall 2004
Scan Conversion of Circles
2D Scan-line Conversion
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Chapter 3 Graphics Output Primitives
Line Drawing Algorithms
Presentation transcript:

Dr. Scott Schaefer Scan Conversion of Lines

2/78 Displays – Cathode Ray Tube

3/78 Displays – Liquid Crystal Displays

4/78 Displays – Plasma

5/78 Displays – Pixels Pixel: the smallest element of picture - Integer position (i,j) - Color information (r,g,b) x y (0,0)

6/78 Problem Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line

7/78 Problem Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line

8/78 Problem Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line

9/78 Special Lines - Horizontal

10/78 Special Lines - Horizontal Increment x by 1, keep y constant

11/78 Special Lines - Vertical

12/78 Special Lines - Vertical Keep x constant, increment y by 1

13/78 Special Lines - Diagonal

14/78 Special Lines - Diagonal Increment x by 1, increment y by 1

15/78 How about Arbitrary Lines?

16/78 Slope-intercept equation for a line: Arbitrary Lines m: slope b: y-intercept

17/78 Slope-intercept equation for a line: How can we compute the equation from (x L,y L ), (x H,y H )? Arbitrary Lines m: slope b: y-intercept

18/78 Slope-intercept equation for a line: How can we compute the equation from (x L,y L ), (x H,y H )? Arbitrary Lines m: slope b: y-intercept

19/78 Arbitrary Lines Assume Other lines by swapping x, y or negating Take steps in x and determine where to fill y

20/78 Simple Algorithm Start from (x L, y L ) and draw to (x H, y H ) where x L < x H ( x 0, y 0 ) = ( x L, y L ) For ( i = 0; i <= x H -x L ; i++ ) DrawPixel ( x i, Round ( y i ) ) x i+1 = x i + 1 y i+1 = m x i+1 + b

21/78 Simple Algorithm Start from (x L, y L ) and draw to (x H, y H ) where x L < x H ( x 0, y 0 ) = ( x L, y L ) For ( i = 0; i <= x H -x L ; i++ ) DrawPixel ( x i, Round ( y i ) ) x i+1 = x i + 1 y i+1 = m ( x i + 1 ) + b

22/78 Simple Algorithm Start from (x L, y L ) and draw to (x H, y H ) where x L < x H ( x 0, y 0 ) = ( x L, y L ) For ( i = 0; i <= x H -x L ; i++ ) DrawPixel ( x i, Round ( y i ) ) x i+1 = x i + 1 y i+1 = m x i + m + b

23/78 Simple Algorithm Start from (x L, y L ) and draw to (x H, y H ) where x L < x H ( x 0, y 0 ) = ( x L, y L ) For ( i = 0; i <= x H -x L ; i++ ) DrawPixel ( x i, Round ( y i ) ) x i+1 = x i + 1 y i+1 = m x i + b + m

24/78 Simple Algorithm Start from (x L, y L ) and draw to (x H, y H ) where x L < x H ( x 0, y 0 ) = ( x L, y L ) For ( i = 0; i <= x H -x L ; i++ ) DrawPixel ( x i, Round ( y i ) ) x i+1 = x i + 1 y i+1 = m x i + b + m

25/78 Simple Algorithm Start from (x L, y L ) and draw to (x H, y H ) where x L < x H ( x 0, y 0 ) = ( x L, y L ) For ( i = 0; i <= x H -x L ; i++ ) DrawPixel ( x i, Round ( y i ) ) x i+1 = x i + 1 y i+1 = y i + m

26/78 Simple Algorithm - Example

27/78 Simple Algorithm - Example

28/78 Simple Algorithm - Example

29/78 Simple Algorithm - Example

30/78 Simple Algorithm - Example

31/78 Simple Algorithm - Example

32/78 Simple Algorithm - Example

33/78 Simple Algorithm - Example

34/78 Simple Algorithm - Example

35/78 Simple Algorithm - Problems Floating point operations Rounding Can we do better? ( x 0, y 0 ) = ( x L, y L ) For ( i = 0; i <= x H -x L ; i++ ) DrawPixel ( x i, Round ( y i ) ) x i+1 = x i + 1 y i+1 = y i + m

36/78 Midpoint Algorithm Given a point just drawn, determine whether we move E or NE on next step

37/78 Midpoint Algorithm Given a point just drawn, determine whether we move E or NE on next step Is the line above or below ? Below: move E Above: move NE

38/78 Midpoint Algorithm

39/78 Midpoint Algorithm – Implicit Forms How do we tell if a point is above or below the line?

40/78 Midpoint Algorithm – Implicit Forms How do we tell if a point is above or below the line?

41/78 Midpoint Algorithm – Implicit Forms How do we tell if a point is above or below the line?

42/78 Midpoint Algorithm – Implicit Forms How do we tell if a point is above or below the line?

43/78 Midpoint Algorithm – Implicit Forms How do we tell if a point is above or below the line?

44/78 Midpoint Algorithm – Implicit Forms How do we tell if a point is above or below the line?

45/78 Midpoint Algorithm – Implicit Forms How do we tell if a point is above or below the line? Properties f(x,y)=0 (x,y) on the line f(x,y)<0 (x,y) below the line f(x,y)>0 (x,y) above the line

46/78 Midpoint Algorithm – Implicit Forms

47/78 Midpoint Algorithm – Implicit Forms

48/78 Midpoint Algorithm – Implicit Forms

49/78 Midpoint Algorithm – Implicit Forms

50/78 Midpoint Algorithm – Implicit Forms

51/78 Midpoint Algorithm – Implicit Forms

52/78 Need value of to decide E or NE Build incremental algorithm Assume we have value of  Find value of if E chosen  Find value of if NE chosen Midpoint Algorithm

53/78 Midpoint Algorithm Need value of to decide E or NE Build incremental algorithm Assume we have value of  Find value of if E chosen  Find value of if NE chosen

54/78 Midpoint Algorithm If E was chosen, find

55/78 Midpoint Algorithm If E was chosen, find

56/78 Midpoint Algorithm If NE was chosen, find

57/78 Midpoint Algorithm If NE was chosen, find

58/78 Midpoint Algorithm What about starting value?

59/78 Midpoint Algorithm What about starting value?

60/78 Midpoint Algorithm What about starting value? is on the line!

61/78 Midpoint Algorithm What about starting value?

62/78 Midpoint Algorithm What about starting value? Multiplying coefficients by 2 doesn’t change sign of f

63/78 Midpoint Algorithm – Summary x=x L y=y L d=x H - x L c=y L - y H sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

64/78 Midpoint Algorithm – Summary x=x L y=y L d=x H - x L c=y L - y H sum=2c+d //initial value draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

65/78 Midpoint Algorithm – Summary x=x L y=y L d=x H - x L c=y L - y H sum=2c+d //initial value draw(x,y) while ( x < x H ) // iterate until reaching the end point if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

66/78 Midpoint Algorithm – Summary x=x L y=y L d=x H - x L c=y L - y H sum=2c+d //initial value draw(x,y) while ( x < x H ) // iterate until reaching the end point if ( sum < 0 ) // below the line and choose NE sum += 2d y++ x++ sum += 2c draw(x,y)

67/78 Midpoint Algorithm – Example x=x L y=y L d=x H - x L c=y L - y H sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

68/78 Midpoint Algorithm – Example x=x L y=y L d=6 c=-2 sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

69/78 Midpoint Algorithm – Example x=x L y=y L d=6 c=-2 sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

70/78 Midpoint Algorithm – Example x=x L y=y L d=6 c=-2 sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

71/78 Midpoint Algorithm – Example x=x L y=y L d=6 c=-2 sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

72/78 Midpoint Algorithm – Example x=x L y=y L d=6 c=-2 sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

73/78 Midpoint Algorithm – Example x=x L y=y L d=6 c=-2 sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

74/78 Midpoint Algorithm – Example x=x L y=y L d=6 c=-2 sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

75/78 Midpoint Algorithm – Example x=x L y=y L d=6 c=-2 sum=2c+d draw(x,y) while ( x < x H ) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c draw(x,y)

76/78 Midpoint Algorithm Only integer operations Exactly the same as the more commonly found Bresenham’s line drawing algorithm Extends to other types of shapes (circles)

77/78 Circle, ellipse, etc… Need implicit forms - circle: - ellipse: Equations for incremental calculations Initial positions More details in section of the textbook

78/78 OpenGL: Drawing Lines glBegin (GL_LINES); glVertex2f (p1.x, p1.y); glVertex2f (p2.x, p2.y); glVertex2f (p3.x, p3.y); glVertex2f (p4.x, p4.y); glVertex2f (p5.x, p5.y); glVertex2f (p6.x, p6.y); glEnd(); P1 P2P3 P4 P5P6