Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 445 / 645 Introduction to Computer Graphics Lecture 9 Clipping Clipping.

Similar presentations


Presentation on theme: "CS 445 / 645 Introduction to Computer Graphics Lecture 9 Clipping Clipping."— Presentation transcript:

1 CS 445 / 645 Introduction to Computer Graphics Lecture 9 Clipping Clipping

2 Assignment 1 Do a writeup (call it README) Indicate which version of Visual Studio you usedIndicate which version of Visual Studio you used Also indicate what you do for extra creditAlso indicate what you do for extra credit Also, if your program doesn’t work, explain what you did to help us provide partial creditAlso, if your program doesn’t work, explain what you did to help us provide partial credit Copy all code (including source) required to run your program to username/Assignment1username/Assignment1 Name executable assign1.exeassign1.exe Do a writeup (call it README) Indicate which version of Visual Studio you usedIndicate which version of Visual Studio you used Also indicate what you do for extra creditAlso indicate what you do for extra credit Also, if your program doesn’t work, explain what you did to help us provide partial creditAlso, if your program doesn’t work, explain what you did to help us provide partial credit Copy all code (including source) required to run your program to username/Assignment1username/Assignment1 Name executable assign1.exeassign1.exe

3 Review: Polygon Rasterization AB DC F E H G For scanline, determine all intersections of polygon edges with scanline Sort edge intersections in least to greatest order Use parity count to determine when pixels are drawn Horizontal lines do not contribute to parity count Y min endpoints do contribute to parity count Y max endpoints do not contribute to parity count Bottom edge drawn because A is min of AH. AB does not contribute Not drawn because H is max of AH And HG does not contribute Not drawn because D is min of ED And increments counter to 2. DC doesn’t contribute

4 Next Topic: Clipping We’ve been assuming that all primitives (lines, triangles, polygons) lie entirely within the viewport In general, this assumption will not hold:In general, this assumption will not hold: We’ve been assuming that all primitives (lines, triangles, polygons) lie entirely within the viewport In general, this assumption will not hold:In general, this assumption will not hold:

5 Clipping Analytically calculating the portions of primitives within the viewport

6 Why Clip? Bad idea to rasterize outside of framebuffer bounds Also, don’t waste time scan converting pixels outside window Bad idea to rasterize outside of framebuffer bounds Also, don’t waste time scan converting pixels outside window

7 Clipping The naïve approach to clipping lines: for each line segment for each edge of viewport for each edge of viewport find intersection point find intersection point pick “nearest” point pick “nearest” point if anything is left, draw it if anything is left, draw it What do we mean by “nearest”? How can we optimize this? The naïve approach to clipping lines: for each line segment for each edge of viewport for each edge of viewport find intersection point find intersection point pick “nearest” point pick “nearest” point if anything is left, draw it if anything is left, draw it What do we mean by “nearest”? How can we optimize this? A B C D

8 Trivial Accepts Big optimization: trivial accept/rejects How can we quickly determine whether a line segment is entirely inside the viewport? A: test both endpoints. Big optimization: trivial accept/rejects How can we quickly determine whether a line segment is entirely inside the viewport? A: test both endpoints.

9 Trivial Rejects How can we know a line is outside viewport? A: if both endpoints on wrong side of same edge, can trivially reject line How can we know a line is outside viewport? A: if both endpoints on wrong side of same edge, can trivially reject line

10 Clipping Lines To Viewport Combining trivial accepts/rejects Trivially accept lines with both endpoints inside all edges of the viewportTrivially accept lines with both endpoints inside all edges of the viewport Trivially reject lines with both endpoints outside the same edge of the viewportTrivially reject lines with both endpoints outside the same edge of the viewport Otherwise, reduce to trivial cases by splitting into two segmentsOtherwise, reduce to trivial cases by splitting into two segments Combining trivial accepts/rejects Trivially accept lines with both endpoints inside all edges of the viewportTrivially accept lines with both endpoints inside all edges of the viewport Trivially reject lines with both endpoints outside the same edge of the viewportTrivially reject lines with both endpoints outside the same edge of the viewport Otherwise, reduce to trivial cases by splitting into two segmentsOtherwise, reduce to trivial cases by splitting into two segments

11 Cohen-Sutherland Line Clipping Divide viewplane into regions defined by viewport edges Assign each region a 4-bit outcode: Divide viewplane into regions defined by viewport edges Assign each region a 4-bit outcode: 000000100001 1001 01010100 10001010 0110

12 Cohen-Sutherland Line Clipping Assign an outcode to each vertex of line to test Bit 1 = sign bit of (y max – y)Bit 1 = sign bit of (y max – y) If both outcodes = 0, trivial acceptIf both outcodes = 0, trivial accept –bitwise OR bitwise AND vertex outcodes togetherbitwise AND vertex outcodes together –if result  0, trivial reject Assign an outcode to each vertex of line to test Bit 1 = sign bit of (y max – y)Bit 1 = sign bit of (y max – y) If both outcodes = 0, trivial acceptIf both outcodes = 0, trivial accept –bitwise OR bitwise AND vertex outcodes togetherbitwise AND vertex outcodes together –if result  0, trivial reject

13 Cohen-Sutherland Line Clipping If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded Pick an edge that the line crosses (how?) Intersect line with edge (how?) Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests; repeat if necessary If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded Pick an edge that the line crosses (how?) Intersect line with edge (how?) Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests; repeat if necessary

14 Cohen-Sutherland Line Clipping If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded Pick an edge that the line crosses Check against edges in same order each timeCheck against edges in same order each time –For example: top, bottom, right, left If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded Pick an edge that the line crosses Check against edges in same order each timeCheck against edges in same order each time –For example: top, bottom, right, left A B D E C

15 Cohen-Sutherland Line Clipping Intersect line with edge (how?) A B D E C

16 Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests and repeat if necessary Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests and repeat if necessary Cohen-Sutherland Line Clipping A B D C

17 Viewport Intersection Code (x 1, y 1 ), (x 2, y 2 ) intersect with vertical edge at x right(x 1, y 1 ), (x 2, y 2 ) intersect with vertical edge at x right –y intersect = y 1 + m(x right – x1), m=(y 2 -y 1 )/(x 2 -x 1 ) (x 1, y 1 ), (x 2, y 2 ) intersect with horizontal edge at y bottom(x 1, y 1 ), (x 2, y 2 ) intersect with horizontal edge at y bottom –x intersect = x 1 + (y bottom – y1)/m, m=(y 2 -y 1 )/(x 2 -x 1 ) (x 1, y 1 ), (x 2, y 2 ) intersect with vertical edge at x right(x 1, y 1 ), (x 2, y 2 ) intersect with vertical edge at x right –y intersect = y 1 + m(x right – x1), m=(y 2 -y 1 )/(x 2 -x 1 ) (x 1, y 1 ), (x 2, y 2 ) intersect with horizontal edge at y bottom(x 1, y 1 ), (x 2, y 2 ) intersect with horizontal edge at y bottom –x intersect = x 1 + (y bottom – y1)/m, m=(y 2 -y 1 )/(x 2 -x 1 )

18 Cohen-Sutherland Review Use opcodes to quickly eliminate/include linesUse opcodes to quickly eliminate/include lines –Best algorithm when trivial accepts/rejects are common Must compute viewport clipping of remaining linesMust compute viewport clipping of remaining lines –Non-trivial clipping cost –Redundant clipping of some lines More efficient algorithms exist Use opcodes to quickly eliminate/include linesUse opcodes to quickly eliminate/include lines –Best algorithm when trivial accepts/rejects are common Must compute viewport clipping of remaining linesMust compute viewport clipping of remaining lines –Non-trivial clipping cost –Redundant clipping of some lines More efficient algorithms exist

19 Solving Simultaneous Equations Equation of a line Slope-intercept (explicit equation): y = mx + bSlope-intercept (explicit equation): y = mx + b Implicit Equation: Ax + By + C = 0Implicit Equation: Ax + By + C = 0 Parametric Equation: Line defined by two points, P 0 and P 1Parametric Equation: Line defined by two points, P 0 and P 1 –P(t) = P 0 + (P 1 - P 0 ) t, where P is a vector [x, y] T –x(t) = x 0 + (x 1 - x 0 ) t –y(t) = x 0 + (y 1 - y 0 ) t Equation of a line Slope-intercept (explicit equation): y = mx + bSlope-intercept (explicit equation): y = mx + b Implicit Equation: Ax + By + C = 0Implicit Equation: Ax + By + C = 0 Parametric Equation: Line defined by two points, P 0 and P 1Parametric Equation: Line defined by two points, P 0 and P 1 –P(t) = P 0 + (P 1 - P 0 ) t, where P is a vector [x, y] T –x(t) = x 0 + (x 1 - x 0 ) t –y(t) = x 0 + (y 1 - y 0 ) t

20 Parametric Line Equation Describes a finite line Works with vertical lines (like the viewport edge) 0 <=t <= 1 Defines line between P 0 and P 1Defines line between P 0 and P 1 t < 0 Defines line before P 0Defines line before P 0 t > 1 Defines line after P 1Defines line after P 1 Describes a finite line Works with vertical lines (like the viewport edge) 0 <=t <= 1 Defines line between P 0 and P 1Defines line between P 0 and P 1 t < 0 Defines line before P 0Defines line before P 0 t > 1 Defines line after P 1Defines line after P 1

21 Parametric Lines and Clipping Define each line in parametric form: P 0 (t)…P n-1 (t)P 0 (t)…P n-1 (t) Define each edge of viewport in parametric form: P L (t), P R (t), P T (t), P B (t)P L (t), P R (t), P T (t), P B (t) Could perform Cohen-Sutherland intersection tests using appropriate viewport edge and line Define each line in parametric form: P 0 (t)…P n-1 (t)P 0 (t)…P n-1 (t) Define each edge of viewport in parametric form: P L (t), P R (t), P T (t), P B (t)P L (t), P R (t), P T (t), P B (t) Could perform Cohen-Sutherland intersection tests using appropriate viewport edge and line

22 Line / Edge Clipping Equations Faster line clippers use parametric equations Line 0: x 0 = x 0 0 + (x 0 1 - x 0 0 ) t 0x 0 = x 0 0 + (x 0 1 - x 0 0 ) t 0 y 0 = y 0 0 + (y 0 1 - y 0 0 ) t 0y 0 = y 0 0 + (y 0 1 - y 0 0 ) t 0 Viewport Edge L: x L = x L 0 + (x L 1 - x L 0 ) t Lx L = x L 0 + (x L 1 - x L 0 ) t L y L = y L 0 + (y L 1 - y L 0 ) t Ly L = y L 0 + (y L 1 - y L 0 ) t L x 0 0 + (x 0 1 - x 0 0 ) t 0 = x L 0 + (x L 1 - x L 0 ) t L y 0 0 + (y 0 1 - y 0 0 ) t 0 = y L 0 + (y L 1 - y L 0 ) t L Solve for t 0 and/or t LSolve for t 0 and/or t L Faster line clippers use parametric equations Line 0: x 0 = x 0 0 + (x 0 1 - x 0 0 ) t 0x 0 = x 0 0 + (x 0 1 - x 0 0 ) t 0 y 0 = y 0 0 + (y 0 1 - y 0 0 ) t 0y 0 = y 0 0 + (y 0 1 - y 0 0 ) t 0 Viewport Edge L: x L = x L 0 + (x L 1 - x L 0 ) t Lx L = x L 0 + (x L 1 - x L 0 ) t L y L = y L 0 + (y L 1 - y L 0 ) t Ly L = y L 0 + (y L 1 - y L 0 ) t L x 0 0 + (x 0 1 - x 0 0 ) t 0 = x L 0 + (x L 1 - x L 0 ) t L y 0 0 + (y 0 1 - y 0 0 ) t 0 = y L 0 + (y L 1 - y L 0 ) t L Solve for t 0 and/or t LSolve for t 0 and/or t L

23 Cyrus-Beck Algorithm We wish to optimize line/line intersection Start with parametric equation of line:Start with parametric equation of line: –P(t) = P 0 + (P 1 - P 0 ) t And a point and normal for each edgeAnd a point and normal for each edge –P L, N L We wish to optimize line/line intersection Start with parametric equation of line:Start with parametric equation of line: –P(t) = P 0 + (P 1 - P 0 ) t And a point and normal for each edgeAnd a point and normal for each edge –P L, N L

24 Cyrus-Beck Algorithm Find t such that N L [P(t) - P L ] = 0 Substitute line equation for P(t) Solve for t t = N L [P L – P 0 ] / -N L [P 1 - P 0 ]t = N L [P L – P 0 ] / -N L [P 1 - P 0 ] Find t such that N L [P(t) - P L ] = 0 Substitute line equation for P(t) Solve for t t = N L [P L – P 0 ] / -N L [P 1 - P 0 ]t = N L [P L – P 0 ] / -N L [P 1 - P 0 ] PLPL NLNL P(t) Inside P0P0 P1P1

25 Cyrus-Beck Algorithm Compute t for line intersection with all four edges Discard all (t 1) Classify each remaining intersection as Potentially Entering (PE)Potentially Entering (PE) Potentially Leaving (PL)Potentially Leaving (PL) N L [P 1 - P 0 ] > 0 implies PL N L [P 1 - P 0 ] < 0 implies PE Note that we computed this term when computing tNote that we computed this term when computing t Compute t for line intersection with all four edges Discard all (t 1) Classify each remaining intersection as Potentially Entering (PE)Potentially Entering (PE) Potentially Leaving (PL)Potentially Leaving (PL) N L [P 1 - P 0 ] > 0 implies PL N L [P 1 - P 0 ] < 0 implies PE Note that we computed this term when computing tNote that we computed this term when computing t

26 Compute PE with largest t Compute PL with smallest t Clip to these two points Compute PE with largest t Compute PL with smallest t Clip to these two points Cyrus-Beck Algorithm PE PL P1P1 PE P0P0

27 Cyrus-Beck Algorithm Because of horizontal and vertical clip lines: Many computations reduceMany computations reduce Normals: (-1, 0), (1, 0), (0, -1), (0, 1) Pick constant points on edges solution for t: -(x 0 - x left ) / (x 1 - x 0 )-(x 0 - x left ) / (x 1 - x 0 ) (x 0 - x right ) / -(x 1 - x 0 )(x 0 - x right ) / -(x 1 - x 0 ) -(y 0 - y bottom ) / (y 1 - y 0 )-(y 0 - y bottom ) / (y 1 - y 0 ) (y 0 - y top ) / -(y 1 - y 0 )(y 0 - y top ) / -(y 1 - y 0 ) Because of horizontal and vertical clip lines: Many computations reduceMany computations reduce Normals: (-1, 0), (1, 0), (0, -1), (0, 1) Pick constant points on edges solution for t: -(x 0 - x left ) / (x 1 - x 0 )-(x 0 - x left ) / (x 1 - x 0 ) (x 0 - x right ) / -(x 1 - x 0 )(x 0 - x right ) / -(x 1 - x 0 ) -(y 0 - y bottom ) / (y 1 - y 0 )-(y 0 - y bottom ) / (y 1 - y 0 ) (y 0 - y top ) / -(y 1 - y 0 )(y 0 - y top ) / -(y 1 - y 0 )

28 Comparison Cohen-Sutherland Repeated clipping is expensiveRepeated clipping is expensive Best used when trivial acceptance and rejection is possible for most linesBest used when trivial acceptance and rejection is possible for most linesCyrus-Beck Computation of t-intersections is cheapComputation of t-intersections is cheap Computation of (x,y) clip points is only done onceComputation of (x,y) clip points is only done once Algorithm doesn’t consider trivial accepts/rejectsAlgorithm doesn’t consider trivial accepts/rejects Best when many lines must be clippedBest when many lines must be clipped Liang-Barsky: Optimized Cyrus-Beck Nicholl et al.: Fastest, but doesn’t do 3D Cohen-Sutherland Repeated clipping is expensiveRepeated clipping is expensive Best used when trivial acceptance and rejection is possible for most linesBest used when trivial acceptance and rejection is possible for most linesCyrus-Beck Computation of t-intersections is cheapComputation of t-intersections is cheap Computation of (x,y) clip points is only done onceComputation of (x,y) clip points is only done once Algorithm doesn’t consider trivial accepts/rejectsAlgorithm doesn’t consider trivial accepts/rejects Best when many lines must be clippedBest when many lines must be clipped Liang-Barsky: Optimized Cyrus-Beck Nicholl et al.: Fastest, but doesn’t do 3D

29 Clipping Polygons Clipping polygons is more complex than clipping the individual lines Input: polygonInput: polygon Output: original polygon, new polygon, or nothingOutput: original polygon, new polygon, or nothing When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon? Clipping polygons is more complex than clipping the individual lines Input: polygonInput: polygon Output: original polygon, new polygon, or nothingOutput: original polygon, new polygon, or nothing When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon?

30 What happens to a triangle during clipping? Possible outcomes: What happens to a triangle during clipping? Possible outcomes: triangle  triangle Why Is Clipping Hard? triangle  quad triangle  5-gon How many sides can a clipped triangle have?

31 How many sides? Seven…Seven…

32 A really tough case: Why Is Clipping Hard?

33 A really tough case: Why Is Clipping Hard? concave polygon  multiple polygons

34 Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the viewport edge’s equationClip the polygon against the viewport edge’s equation Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the viewport edge’s equationClip the polygon against the viewport edge’s equation

35 Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

36 Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

37 Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

38 Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

39 Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

40 Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

41 Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

42 Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

43 Sutherland-Hodgeman Clipping: The Algorithm Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

44 Sutherland-Hodgeman Clipping Input/output for algorithm: Input: list of polygon vertices in orderInput: list of polygon vertices in order Output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe)Output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe) Note: this is exactly what we expect from the clipping operation against each edge Input/output for algorithm: Input: list of polygon vertices in orderInput: list of polygon vertices in order Output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe)Output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe) Note: this is exactly what we expect from the clipping operation against each edge

45 Sutherland-Hodgeman Clipping Sutherland-Hodgman basic routine: Go around polygon one vertex at a timeGo around polygon one vertex at a time Current vertex has position pCurrent vertex has position p Previous vertex had position s, and it has been added to the output if appropriatePrevious vertex had position s, and it has been added to the output if appropriate Sutherland-Hodgman basic routine: Go around polygon one vertex at a timeGo around polygon one vertex at a time Current vertex has position pCurrent vertex has position p Previous vertex had position s, and it has been added to the output if appropriatePrevious vertex had position s, and it has been added to the output if appropriate

46 Sutherland-Hodgeman Clipping Edge from s to p takes one of four cases: (Orange line can be a line or a plane) Edge from s to p takes one of four cases: (Orange line can be a line or a plane) insideoutside s p p output insideoutside s p no output insideoutside s p i output insideoutside s p i output p output

47 Sutherland-Hodgeman Clipping Four cases: s inside plane and p inside planes inside plane and p inside plane –Add p to output –Note: s has already been added s inside plane and p outside planes inside plane and p outside plane –Find intersection point i –Add i to output s outside plane and p outside planes outside plane and p outside plane –Add nothing s outside plane and p inside planes outside plane and p inside plane –Find intersection point i –Add i to output, followed by p Four cases: s inside plane and p inside planes inside plane and p inside plane –Add p to output –Note: s has already been added s inside plane and p outside planes inside plane and p outside plane –Find intersection point i –Add i to output s outside plane and p outside planes outside plane and p outside plane –Add nothing s outside plane and p inside planes outside plane and p inside plane –Find intersection point i –Add i to output, followed by p

48 Point-to-Plane test A very general test to determine if a point p is “inside” a plane P, defined by q and n: (p - q) n < 0: p inside P (p - q) n = 0: p on P (p - q) n > 0: p outside P Remember: p n = |p| |n| cos (  )  = angle between p and n A very general test to determine if a point p is “inside” a plane P, defined by q and n: (p - q) n < 0: p inside P (p - q) n = 0: p on P (p - q) n > 0: p outside P Remember: p n = |p| |n| cos (  )  = angle between p and n P n p q P n p q P n p q

49 Finding Line-Plane Intersections Edge intersects plane P where E(t) is on P q is a point on Pq is a point on P n is normal to Pn is normal to P (L(t) - q) n = 0 t = [(q - L 0 ) n] / [(L 1 - L 0 ) n] The intersection point i = L(t) for this value of tThe intersection point i = L(t) for this value of t Edge intersects plane P where E(t) is on P q is a point on Pq is a point on P n is normal to Pn is normal to P (L(t) - q) n = 0 t = [(q - L 0 ) n] / [(L 1 - L 0 ) n] The intersection point i = L(t) for this value of tThe intersection point i = L(t) for this value of t

50 Line-Plane Intersections Again, lots of opportunity for optimization


Download ppt "CS 445 / 645 Introduction to Computer Graphics Lecture 9 Clipping Clipping."

Similar presentations


Ads by Google