2D Clipping Algorithms: Max Max Min Min Max Max Min Min
2D Clipping Algorithms: Max Max Min Min Max Max Min Min
1 if y > y
max
0 if y y
max
B =
1 if y < y
min
0 if y y
min
R =
1 if x > x
max
0 if x x
max
L =
1 if x < x
min
0 if x x
min
Let C
0
and C
1
be the TBRL clip code for P
0
and P
1
, respectively. Then
1: If C
0
= 0 and C
1
= 0 the line is completely inside the domain;
2: If C
0
and C
1
have one or more bits in common, the line is completely outside the
domain;
3: If any of the bits in C
0
or C
1
are set, clip to the corresponding edge as follows, updating
the end points and clip codes as appropriate
T: x = x
0
+ (y
max
y
0
)
x
1
x
0
y
1
y
0
;
B: x = x
0
+ (y
min
y
0
)
x
1
x
0
y
1
y
0
;
R: y = y
0
+ (x
max
x
0
)
y
1
y
0
x
1
x
0
;
L: y = y
0
+ (x
min
x
0
)
y
1
y
0
x
1
x
0
;
Note that after clipping the line may still miss the domain as in the case of line P
Q
P
R
.
Liang-Barsky
Let
P(t) = (1 t)P
0
+tP
1
For P(t) on the same edge as P
e
and hence perpendicular to N,
0 = N [P(t) P
e
]
= N [(1 t)P
0
+tP
1
P
e
]
= N P
0
tN P
0
+tN P
1
N P
e
Bring all terms containing t to the left
tN [P
0
P
1
] = N [P
0
P
e
]
Rearrange
t =
N [P
0
P
e
]
N [P
0
P
1
]
For the left edge N = (1, 0) and P
e
= (x
min
, y) so that
t =
(1, 0) (x
0
x
min
, y
0
y)
(1, 0) (x
0
x
1
, y
0
y
1
)
=
x
min
x
0
x
1
x
0
For the right edge N = (1, 0) and P
e
= (x
max
, y) so that
t =
(1, 0) (x
0
x
max
, y
0
y)
(1, 0) (x
0
x
1
, y
0
y
1
)
=
x
0
x
max
x
0
x
1
For the bottom edge N = (0, 1) and P
e
= (x, y
min
) so that
t =
(0, 1) (x
0
x, y
0
y
min
)
(0, 1) (x
0
x
1
, y
0
y
1
)
=
y
min
y
0
y
1
y
0
For the top edge N = (0, 1) and P
e
= (x, y
max
) so that
t =
(0, 1) (x
0
x, y
0
y
max
)
(0, 1) (x
0
x
1
, y
0
y
1
)
=
y
0
y
max
y
0
y
1