1 CS 430/536 Computer Graphics I Line Drawing Week 1, Lecture 2 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory.

Slides:



Advertisements
Similar presentations
5.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 5 – Drawing A Line.
Advertisements

CS 450: COMPUTER GRAPHICS LINEAR ALGEBRA REVIEW SPRING 2015 DR. MICHAEL J. REALE.
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
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
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
David Breen, William Regli and Maxim Peysakhov
Chapter 4.1 Mathematical Concepts
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
Now Playing: My Mathematical Mind Spoon From Gimme Fiction Released May 10, 2005.
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
MOHAMMAD IMRAN DEPARTMENT OF APPLIED SCIENCES JAHANGIRABAD EDUCATIONAL GROUP OF INSTITUTES.
Vectors.
Computer Graphics (Fall 2005) COMS 4160, Lecture 2: Review of Basic Math
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Matrix Definition A Matrix is an ordered set of numbers, variables or parameters. An example of a matrix can be represented by: The matrix is an ordered.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 2: Review of Basic Math
Geometric Intuition Randy Gaul. Vectors, Points and Basis Matrices Rotation Matrices Dot product and how it’s useful Cross product and how it’s useful.
Mathematical Fundamentals
Chapter 10 Review: Matrix Algebra
Graphics CSE 581 – Interactive Computer Graphics Mathematics for Computer Graphics CSE 581 – Roger Crawfis (slides developed from Korea University slides)
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.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
1 CS 430/536 Computer Graphics I 3D Transformations World Window to Viewport Transformation Week 2, Lecture 4 David Breen, William Regli and Maxim Peysakhov.
Lecture 7 Matrices CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
1 CS 430/536 Computer Graphics I Curve Drawing Algorithms Week 4, Lecture 8 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing.
Matrices Matrices A matrix (say MAY-trix) is a rectan- gular array of objects (usually numbers). An m  n (“m by n”) matrix has exactly m horizontal.
2009/9 1 Matrices(§3.8)  A matrix is a rectangular array of objects (usually numbers).  An m  n (“m by n”) matrix has exactly m horizontal rows, and.
CS559: Computer Graphics Lecture 8: 3D Transforms Li Zhang Spring 2008 Most Slides from Stephen Chenney.
Module #9: Matrices Rosen 5 th ed., §2.7 Now we are moving on to matrices, section 7.
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.
Data Representation. What is data? Data is information that has been translated into a form that is more convenient to process As information take different.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
October 16, 2014Computer Vision Lecture 12: Image Segmentation II 1 Hough Transform The Hough transform is a very general technique for feature detection.
Computer Graphics Matrices
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Lecture 13: Raster Graphics and Scan Conversion
2/28/2016 CS 551 / 645: Introductory Computer Graphics Framebuffer Mathematical Foundations The Rendering Pipeline.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Computer Graphics Mathematical Fundamentals Lecture 10 Taqdees A. Siddiqi
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.
MATRICES A rectangular arrangement of elements is called matrix. Types of matrices: Null matrix: A matrix whose all elements are zero is called a null.
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.
CSCE 441 Lecture 2: Scan Conversion of Lines
Transforms.
Bitmap Image Vectorization using Potrace Algorithm
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
CS 2770: Computer Vision Linear Algebra and Matlab
Fitting Curve Models to Edges
CSCE 441 Lecture 2: Scan Conversion of Lines
Scan Conversion of Circles
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
MATRICES MATRIX OPERATIONS.
(c) University of Wisconsin, CS559
Chapter 3 Graphics Output Primitives
Math review - scalars, vectors, and matrices
Presentation transcript:

1 CS 430/536 Computer Graphics I Line Drawing Week 1, Lecture 2 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory Department of Computer Science Drexel University

2 Outline Math refresher Line drawing Digital differential analyzer Bresenham’s algorithm XPM file format

3 Geometric Preliminaries Affine Geometry –Scalars + Points + Vectors and their ops Euclidian Geometry –Affine Geometry lacks angles, distance –New op: Inner/Dot product, which gives Length, distance, normalization Angle, Orthogonality, Orthogonal projection Projective Geometry

4 Affine Geometry Affine Operations: Affine Combinations:  1 v 1 +  2 v 2 + … +  n v n where v 1,v 2, …,v n are vectors and Example:

5 Mathematical Preliminaries Vector: an n-tuple of real numbers Vector Operations –Vector addition: u + v = w Commutative, associative, identity element (0) –Scalar multiplication: cv Note: Vectors and Points are different –Can not add points –Can find the vector between two points

6 Linear Combinations & Dot Products A linear combination of the vectors v 1, v 2, … v n is any vector of the form  1 v 1 +  2 v 2 + … +  n v n where  i is a real number (i.e. a scalar) Dot Product: a real value u 1 v 1 + u 2 v 2 + … + u n v n written as

7 Fun with Dot Products Euclidian Distance from (x,y) to (0,0) in general: which is just: This is also the length of vector v: ||v|| or |v| Normalization of a vector: Orthogonal vectors:

8 Projections & Angles Angle between vectors, Projection of vectors Pics/Math courtesy of Dave UMD-CP

9 Matrices and Matrix Operators A n-dimensional vector: Matrix Operations: –Addition/Subtraction –Identity –Multiplication Scalar Matrix Multiplication Implementation issue: Where does the index start? (0 or 1, it’s up to you…)

10 Matrix Multiplication [C] = [A][B] Sum over rows & columns Recall: matrix multiplication is not commutative Identity Matrix: 1s on diagonal 0s everywhere else

11 Matrix Determinants A single real number Computed recursively Example: Uses: –Find vector ortho to two other vectors –Determine the plane of a polygon

12 Cross Product Given two non-parallel vectors, A and B A x B calculates third vector C that is orthogonal to A and B A x B = (a y b z - a z b y, a z b x - a x b z, a x b y - a y b x )

13 Matrix Transpose & Inverse Matrix Transpose: Swap rows and cols: Facts about the transpose: Matrix Inverse: Given A, find B such that AB = BA = I B  A -1 (only defined for square matrices)

14 Line Drawing

15 Scan-Conversion Algorithms Scan-Conversion: Computing pixel coordinates for ideal line on 2D raster grid Pixels best visualized as circles/dots –Why? Monitor hardware 1994 Foley/VanDam/Finer/Huges/Phillips ICG

16 Drawing a Line y = mx + B m = ∆y / ∆x Start at leftmost x and increment by 1 Ù ∆x = 1 y i = Round(mx i + B) This is expensive and inefficient Since ∆x = 1, y i+1 = y i + ∆y = y i + m –No more multiplication! This leads to an incremental algorithm

17 Digital Differential Analyzer (DDA) If |slope| is less then 1  ∆x = 1  else ∆y = 1 Check for vertical line  m = ∞ Compute corresponding ∆y (∆x) = m (1/m) x k+1 = x k + ∆x y k+1 = y k + ∆y Round (x,y) for pixel location Issue: Would like to avoid floating point operations 1994 Foley/VanDam/Finer/Huges/Phillips ICG x k+1 ∆x∆x xkxk y k+1 ykyk ∆y

Generalizing DDA If |slope| is less than or equal to 1 –Ending point should be right of starting point If |slope| is greater than 1 –Ending point should be above starting point Vertical line is a special case ∆x = 0 18

19 Bresenham’s Algorithm IBM Basic Idea: –Only integer arithmetic –Incremental Consider the implicit equation for a line: 1994 Foley/VanDam/Finer/Huges/Phillips ICG

20 The Algorithm Assumptions: 0 ≤ slope ≤ 1 Pre-computed: Pics/Math courtesy of Dave UMD-CP

21 Bresenham’s Algorithm Given: implicit line equation: Let: where r and q are points on the line and d x, d y are positive Then: Observe that all of these are integers and: for points above the line for points below the line Now….. Pics/Math courtesy of Dave UMD-CP

22 Bresenham’s Algorithm Suppose we just finished –(assume 0 ≤ slope ≤ 1) other cases symmetric Which pixel next? –E or NE Pics/Math courtesy of Dave UMD-CP M Q

23 Assume: Q = exact y value at y midway between E and NE: Observe: If, then pick E Else pick NE If, it doesn’t matter Bresenham’s Algorithm Pics/Math courtesy of Dave UMD-CP M Q < M Q = M M Q

24 Create “modified” implicit function (2x) Create a decision variable D to select, where D is the value of f at the midpoint: Bresenham’s Algorithm Pics/Math courtesy of Dave UMD-CP M

25 Bresenham’s Algorithm If then M is below the line –NE is the closest pixel If then M is above the line –E is the closest pixel M

26 Bresenham’s Algorithm If then M is below the line –NE is the closest pixel If then M is above the line –E is the closest pixel Note: because we multiplied by 2x, D is now an integer---which is very good news How do we make this incremental??

What increment for computing a new D? Next midpoint is: Hence, increment by: 27 Case I: When E is next Pics/Math courtesy of Dave UMD-CP M

28 Case II: When NE is next What increment for computing a new D? Next midpoint is: Hence, increment by: Pics/Math courtesy of Dave UMD-CP M

29 How to get an initial value for D? Suppose we start at: Initial midpoint is: Then: Pics/Math courtesy of Dave UMD-CP

30 The Algorithm Assumptions: 0 ≤ slope ≤ 1 Pre-computed: Pics/Math courtesy of Dave UMD-CP

31 Generalize Algorithm If q x > r x, swap points If slope > 1, always increment y, conditionally increment x If -1 <= slope < 0, always increment x, conditionally decrement y If slope < -1, always decrement y, conditionally increment x Rework D increments

Generalize Algorithm Reflect line into first case Calculate pixels Reflect pixels back into original orientation 32

33 Bresenham’s Algorithm: Example

34 Bresenham’s Algorithm: Example

35 Bresenham’s Algorithm: Example

36 Bresenham’s Algorithm: Example

37 Bresenham’s Algorithm: Example

38 Bresenham’s Algorithm: Example

39 Bresenham’s Algorithm: Example

40 Bresenham’s Algorithm: Example

41 Bresenham’s Algorithm: Example

42 Some issues with Bresenham’s Algorithms Pixel ‘density’ varies based on slope –straight lines look darker, more pixels per unit length –Endpoint order –Line from P1 to P2 should match P2 to P1 –Always choose E when hitting M, regardless of direction 1994 Foley/VanDam/Finer/Huges/Phillips ICG

43 Some issues with Bresenham’s Algorithms How to handle the line when it hits the clip window? Vertical intersections –Could change line slope –Need to change init cond. Horizontal intersections –Again, changes in the boundary conditions –Can’t just intersect the line w/ the box 1994 Foley/VanDam/Finer/Huges/Phillips ICG

44 XPM Format Encoded pixels C code ASCII Text file Viewable on Unix w/ display On Windows with IrfanVIew Translate w/ convert

45 XPM Basics X PixelMap (XPM) Native file format in X Windows Color cursor and icon bitmaps Files are actually C source code Read by compiler instead of viewer Successor of X BitMap (XBM) B-W format

46 XPM Supports Color

47 XPM: Defining Grayscales and Colors Each pixel specified by an ASCII char key describes the context this color should be used within. You can always use “c” for “color”. Colors can be specified: –color name –“#” followed by the RGB code in hexadecimal RGB – 24 bits (2 characters ‘ 0 ’ - ‘ f ’) for each color.

48 XPM: Specifying Color Color NameRGBColor black # white # ff ff ff # red # ff green # 00 ff 00 blue # ff

49 XPM Example Array of C strings The XPM format assumes the origin (0,0) is in the upper left- hand corner. First string is “width height ncolors cpp” Then you have "ncolors" strings associating characters with colors. And last you have "height" strings of "width" * "chars_per_pixel" characters

50 Arrangements for Presentations Grad students pick dates me your preference Priority - first come, first served

51 Programming assignment 1 Input PostScript-like file Output B/W XPM Primary I/O formats for the course Create data structure to hold points and lines in memory (the world model) Implement 2D translation, rotation and scaling of the world model Implement line drawing and clipping January 20th Get started now!

52 Questions? Go to Assignment 1