Professional Documents
Culture Documents
CG (Line Clipping: Cyrus Beck Line Clipping) : BITS Pilani
CG (Line Clipping: Cyrus Beck Line Clipping) : BITS Pilani
Window
wymax
P3 P
P1
P5 6
P7
P9
P8
wymin
P10
P2
wxmin wxmax
BITS Pilani, Hyderabad Campus
Cyrus-Beck Algorithm
3
BITS Pilani, Hyderabad Campus
Cyrus-Beck Algorithm
P(t)
Outside Inside
P0
Substitute line equation for P(t).
𝑁𝐿 ∙ 𝑃0 + 𝑃1 − 𝑃0 𝑡 − 𝑃𝐿 = 0
Solve for t
𝑁𝐿 ∙[𝑃0 −𝑃𝐿 ] 𝑁𝐿 ∙[𝑃0 −𝑃𝐿 ]
• 𝑡= =
−𝑁𝐿 ∙[𝑃1 −𝑃0 ] −𝑁𝐿 ∙𝐷
4
BITS Pilani, Hyderabad Campus
Cyrus-Beck Algorithm
PL P1
PL
PE
PE
P0
6
• Edges are
processed in the
order L, R, B, T.
• Normals are
inwards.
• 𝑤𝑖 = 𝑃0 − 𝑓𝑖 .
• 𝑓1 = 𝑓3 =
𝐿𝑜𝑤𝑒𝑟 𝑙𝑒𝑓𝑡 𝑐𝑜𝑟𝑛𝑒𝑟
• 𝑓2 = 𝑓4 =
𝑈𝑝𝑝𝑒𝑟 𝑟𝑖𝑔ℎ𝑡 𝑐𝑜𝑟𝑛𝑒𝑟
7
Cyrus-Beck Algorithm
8
BITS Pilani, Hyderabad Campus
Comparison
• Cohen-Sutherland
– Repeated clipping is expensive
– Best used when trivial acceptance and rejection is
possible for most lines
• Cyrus-Beck
– Computation of t-intersections is cheap
– Computation of (x,y) clip points is only done once
– Best when many lines must be clipped
• Liang-Barsky: Optimized Cyrus-Beck
9
BITS Pilani, Hyderabad Campus
Liang Barsky Clipping
Algorithm
• Optimized version of Cyrus-Beck, catered for rectangular
axis-aligned window.
• P(t) = P1 + (P2 – P1) t
• All those points which are inside window satisfy 𝑥𝑚𝑖𝑛 ≤
𝑥1 + ∆𝑥 𝑡 ≤ 𝑥𝑚𝑎𝑥 and 𝑦𝑚𝑖𝑛 ≤ 𝑦1 + ∆𝑦 𝑡 ≤ 𝑦𝑚𝑎𝑥 .
𝑥𝑚𝑖𝑛 ≤ 𝑥1 + ∆𝑥 𝑡 ֜ 𝑥1 − 𝑥𝑚𝑖𝑛 ≥ −∆𝑥 𝑡 ֜ 𝑞1 ≥ 𝑝1 𝑡.
𝑥𝑚𝑎𝑥 ≥ 𝑥1 + ∆𝑥 𝑡 ֜ 𝑥𝑚𝑎𝑥 − 𝑥1 ≥ ∆𝑥 𝑡 ֜ 𝑞2 ≥ 𝑝2 𝑡.
10
BITS Pilani, Hyderabad Campus
Liang Barsky Clipping
k qk pk pk =0 qk<0
1(Left) 𝑥1 − 𝑥𝑚𝑖𝑛 −∆𝑥 || to y-axis Left of window
2(right) 𝑥𝑚𝑎𝑥 − 𝑥1 ∆𝑥 || to y-axis Right of
window
3(bottom) 𝑦1 − 𝑦𝑚𝑖𝑛 −∆𝑦 || to x-axis Bottom of
window
4(top) 𝑦𝑚𝑎𝑥 − 𝑦1 ∆𝑦 || to x-axis Top of window
11
BITS Pilani, Hyderabad Campus
Liang Barsky Clipping
k qk pk Normal(N) N.(P2-P1) PE(PL)
1(Left) 𝑥1 − 𝑥𝑚𝑖𝑛 −∆𝑥 (-1.i + 0.j) −∆𝑥 = 𝑝1 −∆𝑥 = 𝑝1 < 0(> 0)
2(right) 𝑥𝑚𝑎𝑥 − 𝑥1 ∆𝑥 (1.i + 0.j) ∆𝑥 = 𝑝2 ∆𝑥 = 𝑝2 < 0(> 0)
3(bottom) 𝑦1 − 𝑦𝑚𝑖𝑛 −∆𝑦 (0.i - 1.j) −∆y = 𝑝3 −∆y = 𝑝3 < 0(> 0)
4(top) 𝑦𝑚𝑎𝑥 − 𝑦1 ∆𝑦 (0.i + 1.j) ∆y = 𝑝4 ∆y = 𝑝4 < 0(> 0)
12
BITS Pilani, Hyderabad Campus
Liang-Barsky Line clipping
algorithm
• If pk = 0 and qk < 0 for any k, eliminate the line and stop.
Otherwise proceed to the next step.
• For all k such that pk < 0, calculate rk = qk/pk. Let u1 be
the maximum of the set containing 0 and the calculated r
values.
• For all k such that pk > 0, calculate rk = qk/pk. Let u2 be
the minimum of the set containing 1 and the calculated r
values.
• If u1 > u2, eliminate the line since it is completely outside
the clipping window. Otherwise use u1 and u2 to
calculate the endpoints of the clipped line.
13
BITS Pilani, Hyderabad Campus