Download presentation
Presentation is loading. Please wait.
Published byRandall Weaver Modified over 9 years ago
1
Dr. Scott Schaefer Clipping Lines
2
2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)
3
3/94 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn (x min, y min ) (x max, y max ) (x,y)
4
4/94 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn (x min, y min ) (x max, y max ) (x,y) x min <=x<=x max ? y min <=y<=y max ?
5
5/94 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn (x 1, y 1 ) (x 2, y 2 ) (x min, y min ) (x max, y max ) x min <=x<=x max ? y min <=y<=y max ?
6
6/94 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn (x min, y min ) (x max, y max ) x min <=x 1 <=x max Yes y min <=y 1 <=y max Yes (x 1, y 1 ) (x 2, y 2 )
7
7/94 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn (x min, y min ) (x max, y max ) x min <=x 2 <=x max No y min <=y 2 <=y max Yes (x 1, y 1 ) (x 2, y 2 )
8
8/94 Clipping Lines
9
9/94 Clipping Lines
10
10/94 Clipping Lines Given a line with end-points (x 0, y 0 ), (x 1, y 1 ) and clipping window (x min, y min ), (x max, y max ), determine if line should be drawn and clipped end-points of line to draw. (x 0, y 0 ) (x 1, y 1 ) (x min, y min ) (x max, y max )
11
11/94 Clipping Lines
12
12/94 Clipping Lines – Simple Algorithm If both end-points inside rectangle, draw line Otherwise, intersect line with all edges of rectangle clip that point and repeat test
13
13/94 Clipping Lines – Simple Algorithm
14
14/94 Clipping Lines – Simple Algorithm
15
15/94 Clipping Lines – Simple Algorithm
16
16/94 Clipping Lines – Simple Algorithm
17
17/94 Clipping Lines – Simple Algorithm
18
18/94 Clipping Lines – Simple Algorithm
19
19/94 Clipping Lines – Simple Algorithm
20
20/94 Clipping Lines – Simple Algorithm
21
21/94 Clipping Lines – Simple Algorithm
22
22/94 Clipping Lines – Simple Algorithm
23
23/94 Clipping Lines – Simple Algorithm
24
24/94 Window Intersection (x 1, y 1 ), (x 2, y 2 ) intersect with vertical edge at x right y intersect = y 1 + m(x right – x 1 ) where 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 intersect = x 1 + (y bottom – y 1 )/m where m=(y 2 -y 1 )/(x 2 -x 1 )
25
25/94 Clipping Lines – Simple Algorithm Lots of intersection tests makes algorithm expensive Complicated tests to determine if intersecting rectangle Is there a better way?
26
26/94 Trivial Accepts Big Optimization: trivial accepts/rejects How can we quickly decide whether line segment is entirely inside window Answer: test both endpoints
27
27/94 Trivial Accepts Big Optimization: trivial accepts/rejects How can we quickly decide whether line segment is entirely inside window Answer: test both endpoints
28
28/94 Trivial Rejects How can we know a line is outside of the window Answer: both endpoints on wrong side of same edge, can trivially reject the line
29
29/94 Trivial Rejects How can we know a line is outside of the window Answer: both endpoints on wrong side of same edge, can trivially reject the line
30
30/94 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments
31
31/94 Cohen-Sutherland Algorithm Every end point is assigned to a four-digit binary value, i.e. Region code Each bit position indicates whether the point is inside or outside of a specific window edge bit 4bit 3bit 2bit 1 leftrightbottomtop
32
32/94 Cohen-Sutherland Algorithm
33
33/94 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments
34
34/94 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments
35
35/94 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments Line is outside the window! reject
36
36/94 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments Line is inside the window! draw
37
37/94 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments
38
38/94 Cohen-Sutherland Algorithm
39
39/94 Cohen-Sutherland Algorithm
40
40/94 Cohen-Sutherland Algorithm
41
41/94 Cohen-Sutherland Algorithm
42
42/94 Cohen-Sutherland Algorithm
43
43/94 Cohen-Sutherland Algorithm
44
44/94 Cohen-Sutherland Algorithm
45
45/94 Cohen-Sutherland Algorithm
46
46/94 Cohen-Sutherland Algorithm
47
47/94 Cohen-Sutherland Algorithm
48
48/94 Cohen-Sutherland Algorithm
49
49/94 Cohen-Sutherland Algorithm
50
50/94 Cohen-Sutherland Algorithm
51
51/94 Cohen-Sutherland Algorithm
52
52/94 Cohen-Sutherland Algorithm
53
53/94 Liang-Barsky Algorithm Uses parametric form of line for clipping Lines are oriented Classify lines as moving inside to out or outside to in Don’t find actual intersection points Find parameter values on line to draw
54
54/94 Liang-Barsky Algorithm Initialize interval to [t min, t max ]=[0,1] For each boundary Find parametric intersection t with boundary If moving in to out, t max = min(t max, t) else t min = max(t min, t) If t min >t max, reject line
55
55/94 Intersecting Two Parametric Lines
56
56/94 Intersecting Two Parametric Lines
57
57/94 Intersecting Two Parametric Lines
58
58/94 Intersecting Two Parametric Lines
59
59/94 Intersecting Two Parametric Lines
60
60/94 Intersecting Two Parametric Lines Substitute t or s back into equation to find intersection
61
61/94 Liang-Barsky: Classifying Lines
62
62/94 Liang-Barsky: Classifying Lines
63
63/94 Liang-Barsky: Classifying Lines
64
64/94 Liang-Barsky: Classifying Lines
65
65/94 Liang-Barsky: Classifying Lines
66
66/94 Liang-Barsky: Classifying Lines
67
67/94 Liang-Barsky: Classifying Lines
68
68/94 Liang-Barsky: Classifying Lines
69
69/94 Liang-Barsky Algorithm
70
70/94 Liang-Barsky Algorithm
71
71/94 Liang-Barsky Algorithm
72
72/94 Liang-Barsky Algorithm
73
73/94 Liang-Barsky Algorithm
74
74/94 Liang-Barsky Algorithm
75
75/94 Liang-Barsky Algorithm
76
76/94 Liang-Barsky Algorithm
77
77/94 Liang-Barsky Algorithm
78
78/94 Liang-Barsky Algorithm
79
79/94 Liang-Barsky Algorithm
80
80/94 Liang-Barsky Algorithm
81
81/94 Liang-Barsky Algorithm
82
82/94 Liang-Barsky Algorithm
83
83/94 Liang-Barsky Algorithm
84
84/94 Liang-Barsky Algorithm
85
85/94 Liang-Barsky Algorithm
86
86/94 Liang-Barsky Algorithm
87
87/94 Liang-Barsky Algorithm
88
88/94 Liang-Barsky Algorithm
89
89/94 Liang-Barsky Algorithm
90
90/94 Liang-Barsky Algorithm
91
91/94 Liang-Barsky Algorithm
92
92/94 Liang-Barsky Algorithm
93
93/94 Comparison Cohen-Sutherland Repeated clipping is expensive Best used when trivial acceptance and rejection is possible for most lines Liang-Barsky Computation of t-intersections is cheap (only one division) Computation of (x,y) clip points is only done once Algorithm doesn’t consider trivial accepts/rejects Best when many lines must be clipped
94
94/94 Line Clipping – Considerations Just clipping end-points does not produce the correct results inside the window Must also update sum in midpoint algorithm Clipping against non-rectangular polygons is also possible but seldom used
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.