Docsity

Computer Graphics I: Line Clipping and 2D Transformations - Prof. David E. Breen, Assignments of Computer Graphics

Toggle sidebar
bg1
1
1
CS 430/536
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 #1
Lecture Credits: Most pictures are from Foley/VanDam;
Additional and extensive thanks also goes to those
credited on individual slides
3
Scissoring Clipping
Pics/Math courtesy of Dave Mount @ UMD-CP
Performed during scan conversion of the
line (circle, polygon)
Compute the next point (x,y)
If xmin
≤
x
≤
xmax and ymin
≤
y
≤
ymax
Then output the point.
Else do nothing
• Issues with scissoring:
– Too slow
– Does more work then necessary
• Better to clip lines to window, than “draw”
lines that are outside of window
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
6
Cohen-Sutherland
Perform trivial accept and reject
• Assign each end point a location code
• Perform bitwise logical operations on a
line’s location codes
• Accept or reject based on result
• Frequently provides no information
– Then perform more complex line intersection
pf3
pf4
pf5

Partial preview of the text

Download Computer Graphics I: Line Clipping and 2D Transformations - Prof. David E. Breen 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 3

Scissoring Clipping

Pics/Math courtesy of Dave Mount @ UMD-CP

Performed during scan conversion of the

line (circle, polygon)

Compute the next point (x,y) If xmin ≤ x ≤ xmax and ymin ≤ y ≤ ymax Then output the point. Else do nothing

  • Issues with scissoring:
    • Too slow
    • Does more work then necessary
  • Better to clip lines to window, than “draw” lines that are outside of window 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^6

Cohen-Sutherland

Perform trivial accept and reject

  • Assign each end point a location code
  • Perform bitwise logical operations on a

line’s location codes

  • Accept or reject based on result
  • Frequently provides no information
    • Then perform more complex line intersection

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 9 Cohen-Sutherland Otherwise, we clip the lines:
  • We know that there is a bit flip, w.o.l.g. assume its (x 0 ,x 1 )
  • Which bit? Try `em all!
    • suppose its bit 4
    • Then x 0 < WL and we know that x 1 WL
    • We need to find the point: (xc ,yc ) ≥ Pics/Math courtesy of Dave Mount @ UMD-CP 10 Cohen-Sutherland
  • Clearly:
  • Using similar triangles
  • Solving for yc gives Pics/Math courtesy of Dave Mount @ UMD-CP 11 Cohen-Sutherland
  • Replace (x 0 ,y 0 ) with (xc ,yc )
  • 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^12 Parametric Line Clipping
  • Developed by Cyrus and Beck in 1978
  • Used to clip 2D/3D lines against convex polygon/polyhedron
  • Liang and Barsky (1984) algorithm efficient in clipping upright 2D/3D clipping regions
  • Cyrus-Beck may be reduced to more efficient Liang-Barsky case
  • Based on parametric form of a line
  • Line: P(t) = P 0 +t(P 1 -P 0 )

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 21 2D Transforms: Translation
  • Rigid motion of points to new locations
  • Defined with column vectors: as 1994 Foley/VanDam/Finer/Huges/Phillips ICG^22
  • Stretching of points along axes: In matrix form: or just: 2D Transforms: Scale 1994 Foley/VanDam/Finer/Huges/Phillips ICG 23
  • Rotation of points about the origin Positive Angle: CCW Negative Angle: CW Matrix form: or just: 2D Transforms: Rotation 1994 Foley/VanDam/Finer/Huges/Phillips ICG^24 2D Transforms: Rotation
  • Substitute the 1 st^ two equations into the 2nd^ two to get the general equation 1994 Foley/VanDam/Finer/Huges/Phillips ICG r cos(θ + φ) r cos(φ) € x '= x cos( θ) − y sin( θ) y '= x sin( θ) + y cos( θ)

25 Homogeneous Coordinates

  • Observe: translation is treated differently from scaling and rotation
  • Homogeneous coordinates : allows all transformations to be treated as matrix multiplications Example: A 2D point (x,y) is the line (x,y,w), where w is any real #, in 3D homogenous coordinates. To get the point, homogenize by dividing by w (i.e. w=1) 1994 Foley/VanDam/Finer/Huges/Phillips ICG 26 Recall our Affine Transformations Pics/Math courtesy of Dave Mount @ UMD-CP 27 Matrix Representation of 2D Affine Transformations
  • Translation:
  • Scale:
  • Rotation:
  • Shear: Reflection: Fy= 28 Composition of 2D Transforms
  • Rotate about a point P
  • Translate P1 to origin
  • Rotate
  • Translate back to P 1994 Foley/VanDam/Finer/Huges/Phillips ICG 29 Composition of 2D Transforms
  • Scale object around point P
  • P1 to origin
  • Scale
  • Translate back to P
  • Compose into T 1994 Foley/VanDam/Finer/Huges/Phillips ICG P’ = T  P 30 Composition of 2D Transforms
  • Scale + rotate object around point P1 and move to P
  • P1 to origin
  • Scale
  • Rotate
  • Translate to P 1994 Foley/VanDam/Finer/Huges/Phillips ICG