Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

MATERI 05.

CLIPPING: CYRUS-BECK ALGORITHM


2020/2021 - 1 Komputer Grafik
Cyrus & Beck Algorithm
1

 Treat line in parametric form.


 Note line will cross all clip boundaries somewhere :
Cyrus & Beck Algorithm
2

 Treat line in parametric form.


 Note line will cross all clip boundaries somewhere :
 Find all intersections, test afterwards to determine if
they are on the clip rectangle.
 Define a point on the clipping plane and its normal.

 Notice the dot product between a vector from this point


and the intersection is zero.
Flowchart Cyrus Beck Algorithm
3
Cyrus Beck Algorithm
4
Cyrus Beck Algorithm (contd..)
5
Vector Directions
6
Cyrus & Beck algorithm
7

P(t ) = P0 + ( P1 − P0 )t PEJ

P1

N j • [ P(t ) − PEJ ] < 0

P0 N j • [ P(t ) − PEJ ] = 0

N j • [ P(t ) − PEJ ] > 0


Edge Ej
Nj
Cyrus & Beck algorithm
8

P (t ) = P0 + ( P1 − P0 )t Sign of denominator is important.

N j • [ P (t ) − PEJ ] = 0 Must ≠ 0 ( ignore parallel lines ).

Parametric form implies direction.


N j • [ P0 + ( P1 − P0 )t − PEJ ] = 0
Denominator < 0 → point entering clip
region.
N j • [ P0 − PEJ ] + N j • [ P1 − P0 ]t = 0
Denominator > 0 → point leaving clip region.

Let D = ( P1 − P0 ), solve for t


N j • [ P0 − PEJ ]
t=
−Nj •D
Cyrus & Beck algorithm
9

D
θ
Nj

N j • [ P0 − PEJ ]
t=
Edge Ej

−Nj •D
Denominator < 0 → point entering clip region, classify as PE
Denominator > 0 → point leaving clip region, classify as PL
Cyrus & Beck Algorithm
10

Sort PE’s and PL’s according to t.


PL < PE → no intersection
t

t
PE

PL PL

PE

Draw from a PE → PL pair.


Note: PEi = f (boundary point)
11
Lat = Latura (at edge)
Note
12
Example
13

nL = i = [+1 0]
nR= -i= [-1 0]
nT = - ĵ = [0 -1]
nB= +ĵ=[0 +1]
Example
14

w1 = [-1 1] – [0 0] = [-1 1]
D = [ 9 3] – [-1 1] = [10 2]
w1 ⋅ nL = [1 1]⋅[+1 0] = -1
D ⋅ nL = [10 2]⋅[+1 0] = 10
t = (w1 ⋅ nL / D⋅ nL) =
-(-1/10) = 1/10
Example
15
Cases
16
Cases 1: Totally Visible Lines
17
Cases 1
18

(1)
(2)

(1) (2)

(3)

Distance to boundary Directrix or direction of


point from the end line
points equation (3) & its
notes, used to
determine whether
Weighting factor the line(s) intersects
or not with the
window.
Clipping Polygons
19

 Clip polygons by clipping successively against 4


sides.
Clipping Polygons
20

 Clip polygons by clipping successively against all 4


sides
 Can implement as pipelined algorithm (ie special
hardware can do the work)
 Recursively test each edge.
 Form new edge with next vertex
 Call with new edge
Sutherland-Hodgman Clipping
21
Algorithm

Four cases of polygon clipping:

Inside Outside Inside Outside Inside Outside Inside Outside

Output First
Output Second Output
Vertex Intersection Output

Case 1 Case 2. Case 3 Case 4


No
output.
Sutherland-Hodgman Algorithm
22

 Loop round vertices, test each against all 4 clipping


planes in sequence
 Call algorithm again with new edge formed by next
vertex -re-entrant
 No storage requirement between stages
 Easy to implement in hardware
Viewing & Clipping - Summary
23

 Window and View Port


 Clipping cuts out what we do not “see”
 Also reduces unnecessary computation
 Can be done at various levels
24

Akhir Materi 05.

You might also like