Dr' Scott Schaefer - PowerPoint PPT Presentation

1 / 87
About This Presentation
Title:

Dr' Scott Schaefer

Description:

Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine ... Big Optimization: trivial accepts/rejects ... of (x,y) clip points is ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 88
Provided by: symo5
Category:
Tags: big | schaefer | scott

less

Transcript and Presenter's Notes

Title: Dr' Scott Schaefer


1
Clipping Lines
  • Dr. Scott Schaefer

2
Why Clip?
  • We do not want to waste time drawing objects that
    are outside of viewing window (or clipping window)

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

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

(xmax,ymax)
(x,y)
xminltxltxmax?
(xmin,ymin)
yminltyltymax?
5
Clipping Points
  • Given a point (x, y) and clipping window (xmin,
    ymin), (xmax, ymax), determine if the point
    should be drawn

(xmax,ymax)
(x2,y2)
(x1,y1)
xminltxltxmax?
(xmin,ymin)
yminltyltymax?
6
Clipping Points
  • Given a point (x, y) and clipping window (xmin,
    ymin), (xmax, ymax), determine if the point
    should be drawn

(xmax,ymax)
(x2,y2)
(x1,y1)
xminltx1ltxmax Yes
(xmin,ymin)
yminlty1ltymax Yes
7
Clipping Points
  • Given a point (x, y) and clipping window (xmin,
    ymin), (xmax, ymax), determine if the point
    should be drawn

(xmax,ymax)
(x2,y2)
(x1,y1)
xminltx2ltxmax No
(xmin,ymin)
yminlty2ltymax Yes
8
Clipping Lines
9
Clipping Lines
10
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.

(xmax,ymax)
(x1, y1)
(x0, y0)
(xmin,ymin)
11
Clipping Lines
12
Clipping Lines Simple Algorithm
  • If both end-points inside rectangle, draw line
  • If one end-point outside,
  • intersect line with all edges of rectangle
  • clip that point and repeat test

13
Clipping Lines Simple Algorithm
14
Clipping Lines Simple Algorithm
15
Clipping Lines Simple Algorithm
16
Clipping Lines Simple Algorithm
17
Clipping Lines Simple Algorithm
18
Clipping Lines Simple Algorithm
19
Clipping Lines Simple Algorithm
20
Clipping Lines Simple Algorithm
21
Clipping Lines Simple Algorithm
22
Clipping Lines Simple Algorithm
23
Clipping Lines Simple Algorithm
24
Clipping Lines Simple Algorithm
25
Clipping Lines Simple Algorithm
26
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)

27
Clipping Lines Simple Algorithm
  • Lots of intersection tests makes algorithm
    expensive
  • Complicated tests to determine if intersecting
    rectangle
  • Is there a better way?

28
Trivial Accepts
  • Big Optimization trivial accepts/rejects
  • How can we quickly decide whether line segment is
    entirely inside window
  • Answer test both endpoints

29
Trivial Accepts
  • Big Optimization trivial accepts/rejects
  • How can we quickly decide whether line segment is
    entirely inside window
  • Answer test both endpoints

30
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

31
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

32
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

33
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 edges

bit 4
bit 3
bit 2
bit 1
left
right
bottom
top
34
Cohen-Sutherland Algorithm
35
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

36
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

37
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

Line is outside the window! reject
38
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

Line is inside the window! draw
39
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

40
Cohen-Sutherland Algorithm
41
Cohen-Sutherland Algorithm
42
Cohen-Sutherland Algorithm
43
Cohen-Sutherland Algorithm
44
Cohen-Sutherland Algorithm
45
Cohen-Sutherland Algorithm
46
Cohen-Sutherland Algorithm
47
Cohen-Sutherland Algorithm
48
Cohen-Sutherland Algorithm
49
Cohen-Sutherland Algorithm
50
Cohen-Sutherland Algorithm
51
Cohen-Sutherland Algorithm
52
Cohen-Sutherland Algorithm
53
Cohen-Sutherland Algorithm
54
Cohen-Sutherland Algorithm
55
Liang-Barsky Algorithm
  • Uses parametric form of line for clipping
  • Lines are oriented
  • Classify lines as moving inside to out or
    outside to in
  • Dont find actual intersection points
  • Find parameter values on line to draw

56
Intersecting Two Parametric Lines
57
Intersecting Two Parametric Lines
58
Intersecting Two Parametric Lines
59
Intersecting Two Parametric Lines
60
Intersecting Two Parametric Lines
61
Intersecting Two Parametric Lines
Substitute t or s back into equation to find
intersection
62
Liang-Barsky Algorithm
63
Liang-Barsky Algorithm
64
Liang-Barsky Algorithm
65
Liang-Barsky Algorithm
66
Liang-Barsky Algorithm
67
Liang-Barsky Algorithm
68
Liang-Barsky Algorithm
69
Liang-Barsky Algorithm
70
Liang-Barsky Algorithm
71
Liang-Barsky Algorithm
72
Liang-Barsky Algorithm
73
Liang-Barsky Algorithm
74
Liang-Barsky Algorithm
75
Liang-Barsky Algorithm
76
Liang-Barsky Algorithm
77
Liang-Barsky Algorithm
78
Liang-Barsky Algorithm
79
Liang-Barsky Algorithm
80
Liang-Barsky Algorithm
81
Liang-Barsky Algorithm
82
Liang-Barsky Algorithm
83
Liang-Barsky Algorithm
84
Liang-Barsky Algorithm
85
Liang-Barsky Algorithm
86
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 doesnt consider trivial
    accepts/rejects
  • Best when many lines must be clipped

87
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
Write a Comment
User Comments (0)
About PowerShow.com