Docsity

Computer Graphics I: Line Drawing - Lecture Notes from CS 430/536 at Drexel University - P, Lab Reports of Computer Graphics

Partial preview of the text

Download Computer Graphics I: Line Drawing - Lecture Notes from CS 430/536 at Drexel University - P and more Lab Reports Computer Graphics in PDF only on Docsity!

CS 430/

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 http://gicl.cs.drexel.edu

Outline

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

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:

Mathematical Preliminaries

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

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: 2 2

x + y

2 2 2 2 1

n

x + x + + x

x •

x

8

Projections & Angles

  • Angle between vectors,
  • Projection of vectors Pics/Math courtesy of Dave Mount @ UMD-CP €  u ⋅  v =  uv cos( θ)

Matrix Multiplication

• [C] = [A][B]

  • Sum over rows & columns
  • Recall: matrix multiplication is not commutative
  • Identity Matrix : 1s on diagonal 0s everywhere else

Matrix Determinants

  • A single real number
  • Computed recursively
  • Example:
  • Uses:
    • Find vector ortho to two other vectors
    • Determine the plane of a polygon ad bc b d a c = −       det € det( A ) = A i , j (− 1 ) i + j M i , j j = 1 n ∑

Matrix Transpose & Inverse

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

Line Drawing

Drawing a Line

  • y = m x + B
  • m = ∆ y / ∆ x
  • Start at leftmost x and increment by 1  ∆ x = 1
  • y i = Round(m x i + B)
  • This is expensive and inefficient
  • Since ∆ x = 1, y i+ = 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+ = x k + ∆x
  • y k+ = 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+ ∆x x k y k+ y k ∆y

19

Bresenham’s Algorithm

• 1965 @ IBM

  • Basic Idea:
    • Only integer arithmetic
    • Incremental
  • Consider the implicit equation for a line: 1994 Foley/VanDam/Finer/Huges/Phillips ICG

20

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 Mount @ UMD-CP