Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that...

94
Dr. Scott Schaefer Clipping Lines

Transcript of Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that...

Page 1: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

Dr. Scott Schaefer

Clipping Lines

Page 2: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

2/94

Why Clip?

We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

Page 3: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

3/94

Clipping Points

Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn

(xmin,ymin)

(xmax,ymax)

(x,y)

Page 4: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

4/94

Clipping Points

Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn

(xmin,ymin)

(xmax,ymax)

(x,y)

xmin<=x<=xmax?ymin<=y<=ymax?

Page 5: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

5/94

Clipping Points

Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn

(x1,y1)(x2,y2)

(xmin,ymin)

(xmax,ymax)

xmin<=x<=xmax?ymin<=y<=ymax?

Page 6: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

6/94

Clipping Points

Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn

(xmin,ymin)

(xmax,ymax)

xmin<=x1<=xmax Yes

ymin<=y1<=ymax Yes

(x1,y1)(x2,y2)

Page 7: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

7/94

Clipping Points

Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn

(xmin,ymin)

(xmax,ymax)

xmin<=x2<=xmax Noymin<=y2<=ymax Yes

(x1,y1)(x2,y2)

Page 8: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

8/94

Clipping Lines

1P

2P

3P4P

5P

6P

7P

8P9P

10P

Page 9: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

9/94

Clipping Lines

5P

6̂P

7P

8P

9̂P

10P̂

Page 10: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

10/94

Clipping Lines

Given a line with end-points (x0, y0), (x1, y1)

and clipping window (xmin, ymin), (xmax, ymax),

determine if line should be drawn and clipped end-points of line to draw.

(x0, y0)

(x1, y1)

(xmin,ymin)

(xmax,ymax)

Page 11: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

11/94

Clipping Lines

1P

2P

3P4P

5P

6P

7P

8P9P

10P

Page 12: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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

Page 13: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

13/94

Clipping Lines – Simple Algorithm

),( 00 yx

),( minmin yx

),( maxmax yx

),( 11 yx

Page 14: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

14/94

Clipping Lines – Simple Algorithm

),( 00 yx

),( minmin yx

),( maxmax yx

),( 11 yx

Page 15: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

15/94

Clipping Lines – Simple Algorithm

)ˆ,ˆ( 00 yx

),( minmin yx

),( maxmax yx

),( 11 yx

Page 16: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

16/94

Clipping Lines – Simple Algorithm

)ˆ,ˆ( 00 yx

),( minmin yx

),( maxmax yx

),( 11 yx

Page 17: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

17/94

Clipping Lines – Simple Algorithm

)ˆ,ˆ( 00 yx

),( minmin yx

),( maxmax yx

),( 11 yx

Page 18: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

18/94

Clipping Lines – Simple Algorithm

)ˆ,ˆ( 00 yx

),( minmin yx

),( maxmax yx

),( 11 yx

Page 19: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

19/94

Clipping Lines – Simple Algorithm

),( 00 yx

),( minmin yx

),( maxmax yx

),( 11 yx

Page 20: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

20/94

Clipping Lines – Simple Algorithm

)ˆ,ˆ( 00 yx

),( minmin yx

),( maxmax yx

),( 11 yx

Page 21: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

21/94

Clipping Lines – Simple Algorithm

)ˆ,ˆ( 00 yx

),( minmin yx

),( maxmax yx

),( 11 yx

Page 22: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

22/94

Clipping Lines – Simple Algorithm

)ˆ,ˆ( 00 yx

),( minmin yx

),( maxmax yx

)ˆ,ˆ( 11 yx

Page 23: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

23/94

Clipping Lines – Simple Algorithm

)ˆ,ˆ( 00 yx

),( minmin yx

),( maxmax yx

)ˆ,ˆ( 11 yx

Page 24: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

24/94

Window Intersection

(x1, y1), (x2, y2) intersect with vertical edge at xright

yintersect = y1 + m(xright – x1)

where m=(y2-y1)/(x2-x1)

(x1, y1), (x2, y2) intersect with horizontal edge at ybottom

xintersect = x1 + (ybottom – y1)/m

where m=(y2-y1)/(x2-x1)

Page 25: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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?

Page 26: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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

Page 27: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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

Page 28: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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

Page 29: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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

Page 30: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

30/94

Cohen-Sutherland Algorithm

Classify p0, p1 using region codes c0, c1

If , trivially reject If , trivially accept Otherwise reduce to trivial cases by splitting

into two segments

010 cc

010 cc

Page 31: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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 4 bit 3 bit 2 bit 1

leftrightbottomtop

Page 32: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

32/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 33: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

33/94

Cohen-Sutherland Algorithm

Classify p0, p1 using region codes c0, c1

If , trivially reject If , trivially accept Otherwise reduce to trivial cases by splitting

into two segments

010 cc

010 cc

Page 34: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

34/94

Cohen-Sutherland Algorithm

Classify p0, p1 using region codes c0, c1

If , trivially reject If , trivially accept Otherwise reduce to trivial cases by splitting

into two segments

010 cc

010 cc

Page 35: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

35/94

Cohen-Sutherland Algorithm

Classify p0, p1 using region codes c0, c1

If , trivially reject If , trivially accept Otherwise reduce to trivial cases by splitting

into two segments

010 cc

010 cc

00000001

0101

1001 1000 1010

0010

01100100

Line is outside the window! reject

Page 36: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

36/94

Cohen-Sutherland Algorithm

Classify p0, p1 using region codes c0, c1

If , trivially reject If , trivially accept Otherwise reduce to trivial cases by splitting

into two segments

010 cc

010 cc

00000001

0101

1001 1000 1010

0010

01100100

Line is inside the window! draw

Page 37: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

37/94

Cohen-Sutherland Algorithm

Classify p0, p1 using region codes c0, c1

If , trivially reject If , trivially accept Otherwise reduce to trivial cases by splitting

into two segments

010 cc

010 cc

00000001

0101

1001 1000 1010

0010

01100100

Page 38: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

38/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 39: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

39/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 40: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

40/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 41: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

41/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 42: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

42/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 43: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

43/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 44: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

44/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 45: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

45/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 46: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

46/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 47: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

47/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 48: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

48/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 49: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

49/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 50: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

50/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 51: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

51/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 52: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

52/94

Cohen-Sutherland Algorithm

00000001

0101

1001 1000 1010

0010

01100100

Page 53: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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

Page 54: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

54/94

Liang-Barsky Algorithm

Initialize interval to [tmin, tmax]=[0,1]

For each boundaryFind parametric intersection t with

boundary If moving in to out, tmax = min(tmax, t)

else tmin = max(tmin, t)

If tmin>tmax, reject line

Page 55: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

55/94

Intersecting Two Parametric Lines

),( 00 yx

),( 22 yx

),( 11 yx

),( 33 yx

Page 56: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

56/94

Intersecting Two Parametric Lines

),( 00 yx

),( 22 yx

),( 11 yxtxxxtx )()( 010 ),( 33 yx

tyyyty )()( 010

10 t

Page 57: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

57/94

Intersecting Two Parametric Lines

),( 00 yx

),( 22 yx

),( 11 yxtxxxtx )()( 010 ),( 33 yx

tyyyty )()( 010

0)0( xx 0)0( yy

1)1( xx 1)1( yy

Page 58: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

58/94

Intersecting Two Parametric Lines

),( 00 yx

),( 22 yx

),( 11 yx

sxxxtxxx )()( 232010

),( 33 yx

syyytyyy )()( 232010

Page 59: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

59/94

Intersecting Two Parametric Lines

),( 00 yx

),( 22 yx

),( 11 yx

02

02

3201

3201

yy

xx

s

t

yyyy

xxxx

),( 33 yx

Page 60: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

60/94

Intersecting Two Parametric Lines

),( 00 yx

),( 22 yx

),( 11 yx

02

02

3201

3201

yy

xx

s

t

yyyy

xxxx

),( 33 yx

Substitute t or s back into equation to find intersection

Page 61: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

61/94

Liang-Barsky: Classifying Lines

)(tp

)0(p

)1(p

outmoving01 xx

Page 62: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

62/94

Liang-Barsky: Classifying Lines

)(tp

)1(p

)0(p

inmoving10 xx

Page 63: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

63/94

Liang-Barsky: Classifying Lines

)(tp

)0(p

)1(p

inmoving01 xx

Page 64: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

64/94

Liang-Barsky: Classifying Lines

)(tp

)1(p

)0(p

outmoving10 xx

Page 65: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

65/94

Liang-Barsky: Classifying Lines

)(tp

)0(p

)1(p

inmoving01 yy

Page 66: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

66/94

Liang-Barsky: Classifying Lines

)(tp

)1(p

)0(p

outmoving10 yy

Page 67: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

67/94

Liang-Barsky: Classifying Lines

)(tp

)0(p

)1(p

outmoving01 yy

Page 68: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

68/94

Liang-Barsky: Classifying Lines

)(tp

)1(p

)0(p

inmoving10 yy

Page 69: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

69/94

Liang-Barsky Algorithm

)(tp

)0(p

)1(p

Page 70: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

70/94

Liang-Barsky Algorithm

)(tp

)0(p

)1(p

Page 71: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

71/94

Liang-Barsky Algorithm

)(tp

)0(p

)1(p

Page 72: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

72/94

Liang-Barsky Algorithm

)(tp

)0(p

)8(.p

Page 73: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

73/94

Liang-Barsky Algorithm

)0(p

)1(p

Page 74: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

74/94

Liang-Barsky Algorithm

)0(p

)1(p

Page 75: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

75/94

Liang-Barsky Algorithm

)0(p

)1(p

Page 76: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

76/94

Liang-Barsky Algorithm

)0(p

)1(p

)7.(p

Page 77: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

77/94

Liang-Barsky Algorithm

)1(p

)0(p

Page 78: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

78/94

Liang-Barsky Algorithm

)1(p

)2(.p

Page 79: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

79/94

Liang-Barsky Algorithm

)1(p

)0(p

Page 80: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

80/94

Liang-Barsky Algorithm

)1(p

)0(p

Page 81: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

81/94

Liang-Barsky Algorithm

)1(p

)1(.p

Page 82: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

82/94

Liang-Barsky Algorithm

)1(p

)1(.p

Page 83: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

83/94

Liang-Barsky Algorithm

)8(.p

)1(.p

Page 84: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

84/94

Liang-Barsky Algorithm

)8(.p

)1(.p

Page 85: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

85/94

Liang-Barsky Algorithm

)8(.p

)1(.p

Page 86: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

86/94

Liang-Barsky Algorithm

)1(p

)0(p

Page 87: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

87/94

Liang-Barsky Algorithm

)1(p

)0(p

Page 88: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

88/94

Liang-Barsky Algorithm

)1(p

)0(p

Page 89: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

89/94

Liang-Barsky Algorithm

)6(.p

)0(p

Page 90: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

90/94

Liang-Barsky Algorithm

)6(.p

)0(p

Page 91: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

91/94

Liang-Barsky Algorithm

)6(.p

)0(p

Page 92: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

92/94

Liang-Barsky Algorithm

)6(.p

)2(.p

Page 93: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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

Page 94: Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

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