Docsity

Line Clipping 2D Transformations - Lecture 3 | CS 430, Assignments of Computer Graphics

Partial preview of the text

Download Line Clipping 2D Transformations - Lecture 3 | CS 430 and more Assignments Computer Graphics in PDF only on Docsity!

1

CS 430/

Computer Graphics I

Line Clipping

2D Transformations

Week 2, Lecture 3 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory Department of Computer Science Drexel University http://gicl.cs.drexel.edu

2

Overview

  • Cohen-Sutherland Line Clipping
  • Parametric Line Clipping
  • 2D Affine transformations
  • Homogeneous coordinates
  • Discussion of homework # Lecture Credits: Most pictures are from Foley/VanDam; Additional and extensive thanks also goes to those credited on individual slides

4

The Cohen-Sutherland Line

Clipping Algorithm

  • How to clip lines to fit in windows? - easy to tell if whole line falls w/in window - harder to tell what part falls inside
  • Consider a straight line
  • And window: Pics/Math courtesy of Dave Mount @ UMD-CP

5

Cohen-Sutherland

Basic Idea:

  • First , do easy test
    • completely inside or outside the box?
  • If no , we need a more complex test
  • Note: we will also need to figure out how line intersects the box Pics/Math courtesy of Dave Mount @ UMD-CP

7

Cohen-Sutherland

  • The Easy Test:
  • Compute 4-bit code based on endpoints P 1 and P 2 Pics/Math courtesy of Dave Mount @ UMD-CP

8

Cohen-Sutherland

  • Line is completely visible iff both code values of endpoints are 0, i.e. - If line segments are completely outside the window, then Pics/Math courtesy of Dave Mount @ UMD-CP

10

Cohen-Sutherland

  • Clearly:
  • Using similar triangles
  • Solving for y c gives Pics/Math courtesy of Dave Mount @ UMD-CP

11

Cohen-Sutherland

  • Replace (x 0 ,y 0 ) with (x c ,y c
  • Re-compute values
  • Continue until all bit flips are processed, i.e. all points are inside the clip window QED Pics/Math courtesy of Dave Mount @ UMD-CP

13

Parametric Line Equation

  • Line: P(t) = P 0 +t(P 1 -P 0 )
  • t value defines a point on the line going through P 0 and P 1
  • 0 <= t <= 1 defines line segment between P 0 and P 1
  • P(0) = P 0 P(1) = P 1 P 0 P 1

14

The Cyrus-Beck Technique

  • Cohen-Sutherland algorithm computes (x,y) intersections of the line and clipping edge
  • Cyrus-Beck finds a value of parameter t for intersections of the line and clipping edges
  • Simple comparisons used to find actual intersection points
  • Liang-Barsky optimizes it by examining t values as they are generated to reject some line segments immediately

16

Calculating N

i

N

i for window edges

  • WT: (0,1) WB: (0, -1) WL: (-1,0) WR: (1,0) N i for arbitrary edges
  • Calculate edge direction
    • E = (V 1 - V 0 ) / |V 1 - V 0 |
    • Be sure to process edges in CCW order
  • Rotate direction vector -90° Nx = Ey Ny = -Ex

17

Finding the Line Segment

  • Calculate intersection points between line and every window line
  • Classify points as potentially entering (PE) or leaving (PL)
  • PE if crosses edge into inside half plane => angle P 0 P 1 and Ni greater 90 ° => Ni • D < 0
  • PL otherwise.
  • Find Te = max(te)
  • Find Tl = min(tl)
  • Discard if Te > Tl
  • If Te < 0 Te = 0
  • If Tl > 1 Tl = 1
  • Use Te, Tl to compute intersection coordinates (x e,ye), (x l,yl) 1994 Foley/VanDam/Finer/Huges/Phillips ICG

19

2D Affine Transformations

All represented as matrix operations on vectors! Parallel lines preserved, angles/lengths not

  • Scale
  • Rotate
  • Translate
  • Reflect
  • Shear Pics/Math courtesy of Dave Mount @ UMD-CP

20

2D Affine Transformations

  • Example 1: rotation and non uniform scale on unit cube
  • Example 2: shear first in x, then in y Note:
  • Preserves parallels
  • Does not preserve lengths and angles 1994 Foley/VanDam/Finer/Huges/Phillips ICG