Scan Conversion of Lines

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.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
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 Algorithms
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.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
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.
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..
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
1 CS 430/536 Computer Graphics I Circle Drawing and Clipping Week 3, Lecture 6 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
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.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
1 Circle Drawing Algorithms Pictures snagged from
CGMB214: Introduction to Computer Graphics
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
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.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
Scan Conversion.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
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.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Line Drawing Algorithms
Scan Conversion or Rasterization
Computer Graphics Drawing Line.
CSCE 441 Lecture 2: Scan Conversion of Lines
CS G140 Graduate Computer Graphics
(c) 2002 University of Wisconsin, CS559
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
Computer Graphics Implementation I.
Prof. Harriet Fell Spring 2007 Lecture 5 – January 17, 2006
Chapter Three Part I Output Primitives CS 380.
Computer Graphics 5: Line Drawing Algorithms
Computer Graphics 5: Line Drawing Algorithms
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.
Computer Graphics 5: Line Drawing Algorithms
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Chapter 3 Graphics Output Primitives
Presentation transcript:

Scan Conversion of Lines Dr. Scott Schaefer

Displays – Cathode Ray Tube

Displays – Liquid Crystal Displays

Displays – Light-Emitting Diode

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

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

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

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

Special Lines - Horizontal

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

Special Lines - Vertical

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

Special Lines - Diagonal

Special Lines - Diagonal Increment x by 1, increment y by 1

How about Arbitrary Lines?

Arbitrary Lines Slope-intercept equation for a line: m: slope b: y-intercept Slope-intercept equation for a straight line. Here me is the slope of the line and b is the y intercept

Arbitrary Lines Slope-intercept equation for a line: How can we compute the equation from (xL,yL), (xH,yH)? m: slope b: y-intercept Slope-intercept equation for a straight line. Here me is the slope of the line and b is the y intercept

Arbitrary Lines Slope-intercept equation for a line: How can we compute the equation from (xL,yL), (xH,yH)? m: slope b: y-intercept Slope-intercept equation for a straight line. Here me is the slope of the line and b is the y intercept

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

Simple Algorithm Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = m xi+1 + b

Simple Algorithm Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = m ( xi + 1 ) + b

Simple Algorithm Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = m xi + m + b

Simple Algorithm Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = m xi + b + m

Simple Algorithm Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = m xi + b + m

Simple Algorithm Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = yi + m

Simple Algorithm - Example

Simple Algorithm - Example

Simple Algorithm - Example

Simple Algorithm - Example

Simple Algorithm - Example

Simple Algorithm - Example

Simple Algorithm - Example

Simple Algorithm - Example

Simple Algorithm - Example

Simple Algorithm - Problems Floating point operations Rounding Can we do better? ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi ) ) xi+1 = xi + 1 yi+1 = yi + m

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

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

Midpoint Algorithm

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

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

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

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

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

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

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

Midpoint Algorithm – Implicit Forms

Midpoint Algorithm – Implicit Forms

Midpoint Algorithm – Implicit Forms

Midpoint Algorithm – Implicit Forms

Midpoint Algorithm – Implicit Forms

Midpoint Algorithm – Implicit Forms

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

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

Midpoint Algorithm If E was chosen, find

Midpoint Algorithm If E was chosen, find

Midpoint Algorithm If NE was chosen, find

Midpoint Algorithm If NE was chosen, find

What about starting value? Midpoint Algorithm What about starting value?

What about starting value? Midpoint Algorithm What about starting value?

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

What about starting value? Midpoint Algorithm What about starting value?

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

Midpoint Algorithm – Summary x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Summary x=xL y=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Summary x=xL y=yL d=xH - xL c=yL - yH sum=2c+d //initial value draw(x,y) while ( x < xH) // iterate until reaching the end point if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

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

Midpoint Algorithm – Example x=xL y=yL d=xH - xL c=yL - yH sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Example x=xL y=yL d=6 c=-2 sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Example x=xL y=yL d=6 c=-2 sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Example x=xL y=yL d=6 c=-2 sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Example x=xL y=yL d=6 c=-2 sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Example x=xL y=yL d=6 c=-2 sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Example x=xL y=yL d=6 c=-2 sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Example x=xL y=yL d=6 c=-2 sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

Midpoint Algorithm – Example x=xL y=yL d=6 c=-2 sum=2c+d draw(x,y) while ( x < xH) if ( sum < 0 ) sum += 2d y++ x++ sum += 2c

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)

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

OpenGL: Drawing Lines glBegin (GL_LINES); glVertex2f (p1.x, p1.y); glEnd(); P6 P5 P1 P4 P2 P3