Documente Academic
Documente Profesional
Documente Cultură
Clipping
• Cohen Sutherland Algorithm (Line)
• Cyrus-Back Algorithm (Line)
• Sutherland-Hodgeman Algorithm (Polygon)
• Cohen Sutherland Algorithm (3d)
Point Clipping
clip
rectangle y = ymax (xmax, ymax)
x = xmin x = xmax
(x1, y1)
x = xmin x = xmax
clip
rectangle
B B
A A
clip
rectangle
D' D'
C C
B B
A A
clip
rectangle
F
D
D' D'
C C
B B
E
A A
clip
rectangle
F
D
D' D'
C C
B H B
E
H' H'
A A
G' G'
clip G
rectangle
F
D
D' D'
C C
B H B
E
H' J H'
A A
G' G'
J'
clip G
rectangle I'
(x, y) (xb, yb) (xa, ya) (xb, yb) (x, y) (xa, ya)
clip clip
rectangle rectangle
x x0 tline x1 x0 , y y0 tline y1 y0
x xa tedge xb xa , y ya tedge yb ya
Cohen-Sutherland Algorithm
The Cohen-Sutherland Line-Clipping
Algorithm performs initial tests on a line to
determine whether intersection calculations
can be avoided.
1. First, end-point pairs are checked for Trivial
Acceptance.
2. If the line cannot be trivially accepted, region
checks are done for Trivial Rejection.
3. If the line segment can be neither trivially
accepted or rejected, it is divided into two
segments at a clip edge, so that one segment
can be trivially rejected.
These three steps are performed iteratively
until what remains can be trivially accepted or
rejected.
Cohen-Sutherland Algorithm
Region outcodes
Cohen-Sutherland Algorithm
1. A line segment can be trivially
accepted if the outcodes of both the
endpoints are zero.
2. A line segment can be trivially
rejected if the logical AND of the
outcodes of the endpoints is not zero.
3. A key property of the outcode is that
bits that are set in nonzero outcode
correspond to edges crossed.
Cohen-Sutherland Algorithm
clip C
rectangle
B
A
An Example
Cohen-Sutherland Algorithm
clip C
rectangle
An Example
Cohen-Sutherland Algorithm
clip C
rectangle
An Example
Cohen-Sutherland Algorithm
clip C
rectangle
An Example
Parametric Line-Clipping
(1) This fundamentally different (from Cohen-
Sutherland algorithm) and generally more
efficient algorithm was originally published by
Cyrus and Beck.
(2) Liang and Barsky later independently
developed a more efficient algorithm that is
especially fast in the special cases of upright
2D and 3D clipping regions.They also
introduced more efficient trivial rejection tests
for general clip regions.
The Cyrus-Back Algorithm
Outside of clip region Inside of clip rectangle
Edge Ei Line P0 P1 : Pt P0 P1 P0 t
PEi
Pi t PEi
P1 N i Pt PEi 0
N i Pt PEi 0
N i Pt PEi 0
N i P0 P1 P0 t PEi 0
N P P P t P 0
P0
N i P t PEi 0 i 0 1 0 Ei
Ni N P P
t
i 0 Ei
N i P0 P1
t
N i P0 PEi , D P P
Ni D
0 1
The Cyrus-Back Algorithm
Outside of clip region Inside of clip rectangle
Edge Ei
PEi
Pi t PEi
P1
N i Pt PEi 0
P0
N i Pt PEi 0
N i P t PEi 0
Ni
t exists when
t
N i P0 PEi 1 N i 0
Ni D 2 D 0 P0 P1
3 Ni D 0
The Cyrus-Back Algorithm
P1
t=1
PE Line 1 P1
Line 2 t=1
P1
t=1
PL
PL PL
PL
P0
PE
t=0 Line 3
P0
t=0
PE
PE
P0
t=0 Clip
rectangle
Example
Polygon Clipping
Example
Polygon Clipping
Example
Sutherland-Hodgeman Algo.
Clip
Clip
Clip
Against
Against
Against
TheBottom
Clipped
Right
Left
Top Clipping
Clipping
Clipping
Polygon
Boundary
Boundary
Boundary
Initial Condition
4 Cases of Polygon Clipping
Inside Outside
i:first output
p
s
p:second output
s
Polygon
being
clipped
p
s
s
p:output (no output)
i:output
Clip
boundary
Case 2
1
3
4
Algorithm
Input vertex P Close Polygon entry
Does SF
No First Point Yes intersect E?
Yes
Compute
F=P Intersection I
No
Does SP intersect
No
E?
Output
Yes
vertex I
Compute
Intersection Point
I
Exit
Output
vertex I
S=P
Is S on left
Yes
side of E?
Output
vertex S
NO
Exit
3D Clipping
• Both the Cohen-Sutherland and Cyrus-Beck clipping algorithm
readily extend to 3D.
• For Cohen-Sutherland algorithm use two extra-bit in outcode for
incorporating z < zmin and z > zmax regions
Thank You