Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Similar documents
Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Rasterization: Geometric Primitives

Chapter - 2: Geometry and Line Generations

Rasterization, or What is glbegin(gl_lines) really doing?

From Ver(ces to Fragments: Rasteriza(on

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

MODULE - 4. e-pg Pathshala

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Overview of Computer Graphics

Line Drawing Week 6, Lecture 9

CS 450: COMPUTER GRAPHICS RASTERIZING LINES SPRING 2016 DR. MICHAEL J. REALE

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

GRAPHICS OUTPUT PRIMITIVES

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

Einführung in Visual Computing

UNIT -8 IMPLEMENTATION

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

Painter s HSR Algorithm

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

UNIT 2 GRAPHIC PRIMITIVES

Computer Graphics: Line Drawing Algorithms

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

Points and lines. x x 1 + y 1. y = mx + b

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007

Computer Graphics. Lecture 3 Graphics Output Primitives. Somsak Walairacht, Computer Engineering, KMITL

Pipeline implementation II

Chapter 8: Implementation- Clipping and Rasterization

Computer Graphics D Graphics Algorithms

Implementation III. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Efficient Plotting Algorithm

Raster Displays and Scan Conversion. Computer Graphics, CSCD18 Fall 2008 Instructor: Leonid Sigal

Graphics Output Primitives

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

Computer Graphics Lecture Notes

(Refer Slide Time: 9:36)

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Chapter 3. Sukhwinder Singh

Display Technologies: CRTs Raster Displays

CS Rasterization. Junqiao Zhao 赵君峤

SNAP Centre Workshop. Graphing Lines

CSCI 4620/8626. Coordinate Reference Frames

A New Line Drawing Algorithm Based on Sample Rate Conversion

COMP371 COMPUTER GRAPHICS

Scan Converting Lines

1 Introduction to Graphics

Introduction to Computer Graphics (CS602) Lecture 05 Line Drawing Techniques

CS 543: Computer Graphics. Rasterization

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

An Improved Algorithm for Scan-converting a Line

(Refer Slide Time: 00:03:51)

Computer Graphics. Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

Computer Graphics. Chapter 3 Computer Graphics Software

CS6504 & Computer Graphics Unit I Page 1

Department of Computer Science Engineering, Mits - Jadan, Pali, Rajasthan, India

2.4. A LIBRARY OF PARENT FUNCTIONS

Line Drawing. Foundations of Computer Graphics Torsten Möller

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

RASTERIZING POLYGONS IN IMAGE SPACE

Section 1.1 The Distance and Midpoint Formulas; Graphing Utilities; Introduction to Graphing Equations

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science

Rendering. A simple X program to illustrate rendering

Rendering. A simple X program to illustrate rendering

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Scan Conversion. Drawing Lines Drawing Circles

CS2401 Computer Graphics

CS452/552; EE465/505. Clipping & Scan Conversion

Computer Graphics: 6-Rasterization

EF432. Introduction to spagetti and meatballs

Graphics (Output) Primitives. Chapters 3 & 4

Topic #1: Rasterization (Scan Conversion)

Unit 2 Output Primitives and their Attributes

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

Vertical and Horizontal Translations

Practice Test (page 391) 1. For each line, count squares on the grid to determine the rise and the run. Use slope = rise

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object...

Topics. From vertices to fragments

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

Output Primitives Lecture: 4. Lecture 4

Realtime 3D Computer Graphics Virtual Reality

slope rise run Definition of Slope

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

Computer Graphics D Graphics Algorithms

Notes Lesson 3 4. Positive. Coordinate. lines in the plane can be written in standard form. Horizontal

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

2-5 Graphing Special Functions. Graph each function. Identify the domain and range. SOLUTION:

CPSC / Scan Conversion

Clipping and Scan Conversion

Transcription:

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms By: A. H. Abdul Hafez Abdul.hafez@hku.edu.tr, 1

Outlines 1. Basic concept of lines in OpenGL 2. Line Equation 3. DDA Algorithm 4. DDA Algorithm implementation 5. End 2

Basic concept of lines in OpenGL To display the line on a raster monitor, the graphics system must first project the endpoints to integer screen coordinates Next, it determines the nearest pixel positions along the line path between the two endpoints. Then the line color is loaded into the frame buffer at the corresponding pixel coordinates. 3

Basic concept of lines in OpenGL Reading from the frame buffer, the video controller plots the screen pixels. This process digitizes the line into a set of discrete integer positions that, in general, only approximates the actual line path. This rounding of coordinate values to integers causes all but horizontal and vertical limes to be displayed with a stair-step appearance ("the jaggies"). 4

Line Equation The Cartesian slope-intercept equation for a straight line is we can determine values for the slope m and y intercept b with the following calculations: For any given x interval δx along a line, we can compute the corresponding y interval δy On raster systems, lines are plotted with pixels. That is, we must "sample" a line at discrete positions and determine the nearest pixel to the line at each sampled position. Discrete sample positions along the x axis is shown. 5

DDA Algorithm A line is sampled at unit intervals in one coordinate and the corresponding integer values nearest the line path are determined for the other coordinate. We consider first a line with positive slope; start is at left: 1. If the slope is less than or equal to 1, we sample at unit x intervals (δx = 1) and compute successive y values as 2. For lines with a positive slope greater than 1, we reverse the roles of x and y. That is, we sample at unity intervals (δy = 1) and calculate consecutive x values as In this case, each computed x value is rounded to the nearest pixel position along the current y scan line. 6

DDA Algorithm We consider second a line with positive slope; start is at right: If the slope is less than or equal to 1, we sample at unit x intervals (δx = -1) and compute successive y values as For lines with a slope greater than 1, we sample at unity intervals (δy = -1) and calculate consecutive x values as If the slop is negative, we consider similarly to the two above cases. See next slide for generalization. 7

DDA Algorithm. General case of slope If the absolute value of the-slope-is less than 1 and the starting endpoint is at the left, we set δx = 1 and calculate y values with When the starting endpoint is at the right (for the same slope), we set δx = -1 and obtain y positions using If the absolute value greater than 1 and the starting point at the left, we use δy = -1 and When the starting point is at the right, we use δy = 1 and 8

DDA Algorithm implementation This algorithm is summarized in the following procedure, which accepts as input two integer screen positions for the endpoints of a line segment. Horizontal and vertical differences between the endpoint positions are assigned to parameters dx and dy. The difference with the greater magnitude determines the value of parameter steps. Starting with pixel position (x 0, y 0 ), we determine the offset needed at each step to generate the next pixel position along the line path. We loop through this process steps times. 1. If the magnitude of dx is greater than the magnitude of dy and x 0 is less than x End, the values for the increments in the x and y directions are 1 and m=dy/dx, respectively. 2. If the greater change is in the x direction, but x 0 is greater than x End, then the decrements -1 and m=dy/dx are used to generate each new point on the line. 3. Otherwise, we use a unit increment (or decrement) in the y direction and an x increment (or decrement) of 1/m=dx/dy. 9

DDA Algorithm implementation 10

Bresenham's Line Algorithm Motivation: A section of the screen showing a pixel in column x k on scan line y k that is to be plotted along the path of a line segment with slope 0 < m < 1. Assuming we have determined that the pixel at (x k, y k ) is to be displayed, we next need to decide which pixel to plot in column x k+l = x k + 1. Our choices are the pixels at positions (x k + 1, y k ) and (x k + 1, y k +1). 11 March 6, 2016

Bresenham's Line Algorithm To determine which of the two pixels is closest to the line path, we can set up an efficient test that is based on the difference between the two pixel separations, and defining the decision parameter as Vertical distances between pixel positions and the line y coordinate at sampling position x k + 1. 12 March 6, 2016

Bresenham's Line Algorithm 13

Bresenham's Line Algorithm EXAMPLE 3-1 from the text 14

Bresenham's Line Algorithm EXAMPLE 3-1 cont. 15

Bresenham's Line Algorithm Pixel positions along the line path between endpoints (20, 10) and (30, 18), plotted with Bresenham s line algorithm. 16

Bresenham's Line Algorithm Code 17

Bresenham's Line Algorithm Code 18

The end of the Lecture Thanks for your time Questions are welcome 19