Clipping Polygon Clipping Polygon : Area primitive Simple Polygon: Planar set of ordered points No line crossings No holes V3 V4 V1 V2 Simple Polygon Line Crossing Hole
Clipping Polygon Clipping Polygon : Area primitive Non-Convex Polygon
Clipping Polygon Clipping Sutherland-Hodgman Window must be convex Polygon to be clipped can be convex or non-convex Polygon Polygon Window
Clipping Polygon Clipping Sutherland-Hodgman Window must be convex Polygon to be clipped can be convex or non-convex
Clipping Polygon Clipping Sutherland-Hodgman
Clipping Polygon Clipping Sutherland-Hodgman Approach Polygon to be clipped is given as v1, v2, …, vn Polygon edge is a pair [vi, vi+1] Process all polygon edges in succession against a window edge polygon (v1, v2, …, vn) polygon (w1, w2, …, wm) Repeat on resulting polygon with next window edge
Clipping Polygon Clipping Sutherland-Hodgman Approach Four Cases s = vi is the polygon edge starting vertex p = vi+1 is the polygon edge ending vertex i is a polygon-edge/window-edge intersection point wj is the next polygon vertex to be output
Clipping Polygon Clipping Sutherland-Hodgman Approach Case 1: Polygon edge is entirely inside the window edge Inside Outside s p is next vertex of resulting polygon p wj and j+1 j p Output
Clipping Polygon Clipping Sutherland-Hodgman Approach Case 2: Polygon edge crosses window edge going out Inside Outside Intersection point i is next vertex of resulting polygon i wj and j+1 j p s i Output
Clipping Polygon Clipping Sutherland-Hodgman Approach Case 3: Polygon edge is entirely outside the window edge Inside Outside p No output s
Clipping Polygon Clipping Sutherland-Hodgman Approach Case 4: Polygon edge crosses window edge going in Inside Outside Output s p i Intersection point i and p are next two vertices of resulting polygon i wj and p wj+1 and j+2 j
Clipping Polygon Clipping Sutherland-Hodgman Example s5 s4 s3 s2 s1 Window s1
Clipping Polygon Clipping Sutherland-Hodgman Example s5 s4 i2 i1 s3 s2
Clipping Polygon Clipping Sutherland-Hodgman Example t4 t3 t2 t1 t5
Clipping Polygon Clipping Sutherland-Hodgman Example u3 u2 u1 u5 u4
Clipping Polygon Clipping Sutherland-Hodgman Example v2 i3 v1 i6 v5 i5
Clipping Polygon Clipping Sutherland-Hodgman Example w1 w6 w5 w4 w3 w2
Polygon Scan Conversion Polygon Filling Consider first triangle
Polygon Scan Conversion Polygon Filling Consider first triangle Color all pixels inside triangle Inside (containment) test
Polygon Scan Conversion Polygon Filling Triangle Use horizontal spans. Process horizontal spans in scan-line order. For the next spans use edge slopes XL XR
Polygon Scan Conversion Polygon Filling Polygon How do we decide what parts of the span should be filled ?
Polygon Scan Conversion Polygon Filling Polygon How do we decide what parts of the span should be filled ? Parity check if odd fill if even don’t fill
Polygon Scan Conversion Polygon Filling Polygon What happens here?
Polygon Scan Conversion Polygon Filling Polygon What happens here?
Polygon Scan Conversion Polygon Filling Polygon Recursive seed filling
Geometrical Transformation Translation P ( x , y ) ® P ' ( x ' , y ' ) P’ x ' = x + t ; y ' = y + t x y P T P ' = P + T P = [ x , y ]; T = [ t , t ] x y
Geometrical Transformation Scaling P ( x , y ) ® P ' ( x ' , y ' ) x ' = s x ; y ' = s y x y é s ù x [ x ' , y ' ] = [ x , y ] ê ú s ë û y P ' = P . S
Geometrical Transformation Scaling P ( x , y ) ® P ' ( x ' , y ' ) x ' = s x ; y ' = s y x y é s ù [ x ' ' x , y ] = [ x , y ] ê ú s ë û y P ' = P . S s = s : uniform scaling x y s ¹ s : differenti al scaling x y
Geometrical Transformation Rotation P ( x , y ) ® P ' ( x ' , y ' ) x = r cos( φ ); y = r sin( φ ) x ' = r cos( φ + θ ) P’ y ' = r sin( φ + θ ) q P ' = - f x x cos( θ ) y sin( θ ) y ' = x sin( θ ) + y cos( θ ) é cos( θ ) sin( θ ) ù [ x ' , y ' ] = [ x , y ] ê ú - ë sin( θ ) cos( θ ) û P ' = P . R θ
Geometrical Transformation General 2x2 Matrix X ® X ' X ' = X . T é a b ù [ x ' , y ' ] = [ x , y ] = [( ax + cy ), ( bx + dy )] ê ú ë c d û If a = d = 1 and b = c = 0 T = Identity Matrix X’ = X
Geometrical Transformation General 2x2 Matrix y If b = c = 0 X’ = [ax, dy] : Scaling If b = c = 0 and a = -1, d = 1 X’ = [-x, y] : Reflection P’ P x
Geometrical Transformation General 2x2 Matrix é 1 ù Shearing in X [ x ' , y ' ] = [ x , y ] = [ x + cy , y ] ê ú ë c 1 û
Geometrical Transformation General 2x2 Matrix é 1 b ù Shearing in Y [ x ' , y ' ] = [ x , y ] = [ x , bx + y ] ê ú ë 1 û
Geometrical Transformation Homogenous Coordinates Scale/Rotate/Reflect/Shear: X’ = XT Translate: X’ = X + T P = [ x , y ] P = [ x , y , w ] h Multiple values for the same point e.g., (2, 3, 6) and (4, 6, 12) are same points
Geometrical Transformation Homogenous Coordinates w (x, y,w) (x/w, y/w,1) w=1 x y
Geometrical Transformation Homogenous Coordinates Unifying representation for transformation Transformation matrix from 2x2 to 3x3 X ® X ' X ' = X . T é a b ù ê ú [ x ' , y ' , w ] = [ x , y , 1 ] c d ê ú ë ê l m 1 ú û = [( ax + cy + l ), ( bx + dy + m ), 1 ]
Geometrical Transformation Homogenous Coordinates Translation é 1 ù ê ú T = 1 ê ú ê l m 1 ú ë û X ' = XT [ x ' , y ' ] = [ x + l , y + m ]
Geometrical Transformation Homogenous Coordinates Scaling/Rotation/Shear é a b ù ê ú T = c d ê ú ë ê 1 ú û
Geometrical Transformation Homogenous Coordinates Successive translations: T1 = (l1, m1), T2 = (l2, m2) After T1 After T1 and T2 Successive translations are additive
Geometrical Transformation Homogenous Coordinates Successive scaling: S1 = (sx1, sy1), S2 = (sx2, sy2) After S1 After S1 and S2 Successive scaling is multiplicative
Geometrical Transformation Homogenous Coordinates Successive rotations: R(q), R(f) After R(q) After R(q) and R(f) Successive rotations are additive
Geometrical Transformation Composition of transformation Rotation about arbitrary point y Rotation about origin is known Translate such that P becomes O Rotate (about O) Translate back to P P O x
Geometrical Transformation Composition of transformation Rotation about arbitrary point y Rotation about origin is known Translate such that P becomes O P O x
Geometrical Transformation Composition of transformation Rotation about arbitrary point y Rotation about origin is known Rotate about O O x
Geometrical Transformation Composition of transformation Rotation about arbitrary point y Rotation about origin is known Translate back to P P O x
Geometrical Transformation Composition of transformation Composite transformation
Geometrical Transformation Composition of transformation Reflection about an arbitrary line B y C A O x
Geometrical Transformation Composition of transformation Reflection about an arbitrary line y B Translation C A O x
Geometrical Transformation Composition of transformation Reflection about an arbitrary line y B Rotation A C O x
Geometrical Transformation Composition of transformation Reflection about an arbitrary line y Reflection O x A C B
Geometrical Transformation Composition of transformation Reflection about an arbitrary line y Rotation C O A x B
Geometrical Transformation Composition of transformation Reflection about an arbitrary line y Translation C A O x B
Geometrical Transformation Composition of transformation Given T1 and T2 In general,
Geometrical Transformation Rigid Transformations Square remains square Preserves length and angles Sequence of rotations and translations é r r ù 11 12 ê ú T = r r ê 21 22 ú ê ë l m 1 ú û
Geometrical Transformation Affine Transformations Preserves parallelism Sequence of rotations, translations, scaling and shear Linear transformation is when no translation
Geometrical Transformation General Transformation 3x3 matrix