Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
• Any convex region as window
Parametric line (input line AB):
) 1 , 0 (
; ) (
)
( t == A ++ B −− A t t ∈ ∈ L
A
B
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
P n
• Q
Implicit line (window edge):
Tells us on which side of the line the point Q is.
n P Q
Q
l ( ) == ( −− ).
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
P n
• Q
n P Q
Q
l( ) == ( −− ).
Evaluate
If > 0 inside halfspace of line (plane) If < 0 outside halfspace of line (plane) If = 0 on the line
Should give indications for trivial accept and reject cases.
Inside Outside
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
P n
• Q
n P Q
Q
l ( ) == ( −− ).
Inside Outside
) (
)
( t A t B A
L == ++ −−
Window edge Line segment
0 )
( AND 0
)
( A << l B <<
l
0 )
( AND 0
)
(A >> l B >>
l Trivial Reject Trivial Accept
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
P
n
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
P n
A B
t A B
A t
L ( ) == ++ ( −− )
t for solve
; 0 ))
(
( L t ==
l
n P Q
Q
l ( ) == ( −− ).
0 ).
( ).
(
0 ).
) (
(
0 ).
) ( (
==
−−
++
−− −− −− ==
++ −− ==
n A B
t n P A
n P A
B t A
n P t
L
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
P n
A B
n P B
n P A
n P t A
n B A
n P t A
).
( ).
(
).
( ).
(
).
(
−−
−−
−−
== −−
−−
== −−
Clipping
B
n Which ‘t’ to select ?
(t=0)
(t=1)
Cyrus Beck Line Clipping
(Liang and Barsky)
A
Clipping
A
B
n
(t=0)
(t=1)
Cyrus Beck Line Clipping
(Liang and Barsky)
n A B
D
n A B
n P t A
).
(
).
(
).
(
−−
== −− −−
== −−
D > 0 label t as tE Entering
Clipping
A
B
n
(t=0)
(t=1)
Cyrus Beck Line Clipping
(Liang and Barsky)
n A B
D
n A B
n P t A
).
(
).
(
).
(
−−
== −− −−
== −−
D < 0 label t as tL Leaving
Clipping
A
B
n
(t=0)
(t=1)
Cyrus Beck Line Clipping
(Liang and Barsky)
t of interest:
largest tE smallest tL
max
t
E mint
LClipping
If
Cyrus Beck Line Clipping
(Liang and Barsky)
min max
L
E
t
t >>
Reject
Clipping
Arbitrary Convex Window
P1
V1
Cyrus Beck Line Clipping
(Liang and Barsky)
V2
V3 V4 V5
V6 V7
V8
P2
E1 E2 E3 E4 E5
E6
E7 E8
Clipping
Arbitrary Convex Window
P1
V1
Cyrus Beck Line Clipping
(Liang and Barsky)
V2
V3 V4 V5
V6 V7
V8
P2
E1 E2 E3 E4 E5
E6
E7
E8
Polygon is convex if for all adjacent edges the sign of cross product is same.
positive xE
E
positive xE
E
: :
3 2
2 1
.
.
.
Clipping
Arbitrary Window
Cyrus Beck Line Clipping
(Liang and Barsky)
Polygon is non-convex
negative xE
E
positive xE
E
positive xE
E
: : :
4 3
3 2
2 1
. . .
V1 V2
V3 V4
V5 V6
E1
E2 E3 E4
Clipping
Arbitrary Window
Cyrus Beck Line Clipping
(Liang and Barsky)
V1 V2
V3 V4
V5 V6
E1
E2 E3 E4
Make the polygon convex by adding the edge V3V5
Clip against the convex polygon
=> P3P4
P1
P2
P3
P4
Clipping
Arbitrary Window
Cyrus Beck Line Clipping
(Liang and Barsky)
V3 V4
V5 Clip against the triangle
=> P5P4
Subtract P5P4 from P3P4
=> P3P5
P3
P4 P5