Cohen Sutherland
Cyrus and Beck
Clipping window
(X
max, Y
max, Z
max)
(X
min, Y
min, Z
min)
X
Y Z
Six Regions
If both the region codes of the endpoints are zero then the line can be trivially accepted
Else if Logical AND of these regions codes is non zero then it can be trivially rejected
Region codes
Bit position Bit Value calculation
1 TOP bit value =1if (Zmax-Z) is – ve and if +ve, bit value =0 2 BOTTOM bit value =1if (Z-Zmin) is – ve and if +,ve bit value =0 3 RIGHT bit value =1if (Ymax-Y) is – ve and if +ve, bit value =0 4 LEFT bit value =1 if (Y-Ymin) is – ve and if +ve, bit value =0 5 FRONT bit value =1 if (Xmax-X) is – ve and if +ve, bit value =0 6 REAR bit value =1if (X-Xmin) is – ve and if +ve, bit value =0
T
op
B
ottom
R
ight
L
eft
F
ront
R
ear
Nihar Ranjan Roy
p0(1,-1,-1) to p1(0.5,3,1)
P0=010100 P1=001000
(2,2,2)
(0,0,0)
X
Six planes(Surfaces)
Calculations of ‘t’
P(t)=p
1+(p
2-p
1)t
t=(P(t)-p
1)/(p
2-p
1)
t
top=(Z
max-Z
0)/(Z
1-Z
0)
t
bottom=(Z
min-Z
0)/(Z
1-Z
0)
t
right=(Y
max-Y
0)/(Y
1-Y
0)
t
left=(Y
min-Y
0)/(Y
1-Y
0)
t
front=(X
max-X
0)/(X
1-X
0)
t
back=(X
min-X
0)/(X
1-X
0)
Nihar Ranjan Roy
X
problem
A line from p0(1,-1,-1) to p1(0.5,3,1) is to be clipped against the clipping volume defined by a cube with two diagonally opposite
corners at (0,0,0) & (2,2,2). Use the Cohen
Solution
P0010100 P1001000
P0&P1=000000so the line cannot be trivially accepted or rejected
Looking at the outcode of P0 we find that it must be clipped against the bottom boundary
tbottom=
The intersection with the bottom plane is X(t)=x0+(x1-x0)t=1+(0.5-1)1/2=0.75
Y(t)=y0+(y1-y0)t=-1+(3+1)1/2=1 & Z=zmin=0
2 1 0 1 0 min z z z z
Nihar Ranjan Roy
The out code for the new point p`(0.75,1,0) is 000000. Hence this end does not require clipping.
P1 clip it with respect to right plane Y=ymax=2
tright= =2+1/(3+1)=3/4
P(3/4)=(0.6 ,2,0.5)
The visible portion of the line segment is (0.75,1,0) & (0.6,2,0.5)
0 1
0 max
y y
y y
Consider a convex region R A boundary point f on the
convex region R
An outer normal for one of its
boundaries n
We can distinguish in which
region a point lie by looking at the value of the dot product
n.[p(t)-f]
Nihar Ranjan Roy 10
Cyrus and Beck Algorithm
x y
n
Potential Leaving (PL) and Entering (PE)
ni.[p(t)-f] <0 then the vector p(t)-f is
pointed away from the interior of R Lets call it (PL potentially leaving)
ni.[p(t)-f] =0 then p(t)-f is pointed
parallel to the plane containing f and perpendicular to normal.
ni.[p(t)-f] >0 then p(t)-f is pointed
towards the interior of R, lets call it PE
At the point of intersection
with boundary the condition is
PE vs PL
PE(potentially entering) intersection:
If moving from P0 to P1 causes us to cross an edge to enter
the edge's inside half plane;
PL(potentially leaving) intersection:
If moving from P0 to P1 causes us to leave the edge's inside
half plane.
Ni • P0P1 > 0 ⇒ PL Ni • P0P1 < 0 ⇒ PE
n.[p(t)-f]=0
n.[p1+(p2-p1)t-f]=0
This relation can be applied to each boundary plane or edge of the window to get the intersection points. Thus the general form
equation can be written as
ni.[p1+(p2-p1)t-f]=0
Where i is the edge number
The same equation can also be written as
ni.[p1-f]+ni.[p2-p1]t=0
Let D=p -p //direction of line
Thus ni.wi+(ni.D)t=0
Where D ≠ 0 and i=1,2,3,..
We must select the proper value for t using following tips
1. If t is outside the range 0<=t<=1 then it can be ignored
2. The line can intersect the convex window at most two points, but using the above
equation there can be multiple values of t in the range 0<=t<=1. we have to choose the largest lower limit and smallest upper limit.
3. If Di.ni>0 then equation gives lower limit (PL) value for t and if Di.ni<0 then it gives
upper limit (PE) for value of t.
Nihar Ranjan Roy 14
D n
w n t
i i i i
. .
Cyrus- Beck approach for 3D line clipping
Cyrus beck line clipping technique for 2D can directly be
applicable to 3D line clipping with little modifications
Clipping window is replaced by clipping volume
Instead of convex polygon we deal with convex polyhedron
for the window
Clipping edges are replaced by clip plane
Nihar Ranjan Roy 16
Algorithm
1. Read the two endpoints of the line segment say p0 and p1. 2. Read vertex coordinates of the clipping window/volume 3. Calculate D=p1-p0.
4. Assign boundary point with each particular edge/surface 5. Find outer normal for the corresponding edge/surface 6. Calculate D.n and W=p1-f.
7. If D.n>0
1. tL=-W.n/D.n 2. else
3. tU=-W.n/D.n 4. Endif
8. Repeat step 4 to 7 for each edge/surface of the clipping window 9. Find the maximum lower limit and minimun upper limit
problem
A line from p1(1,-1,-1) to p2(0.5,3,1) is to be clipped against the clipping volume defined by a cube with two diagonally opposite
solution
Outer Normals for each edge/boundary
Point f on boundary Top nt=(0,0,1) 2 2 2
Bottom 0 0 -1 0 0 0
Right 0 1 0 2 2 2
Left 0 -1 0 0 0 0
Front 1 0 0 2 2 2
Rear -1 0 0 0 0 0
D n w n p p n f p n t i i i i i i . . ) .( ) .( 1 2
1
Nihar Ranjan Roy
(2,2,2)
(0,0,0)
X
Plane N f Wi=(P1-f) n.W= n.(p1-f)
n.D Type t
Top 0 0 1 2 2 2 (-1 -3 -3) -3 2 PL 𝟑
𝟐=1.5
Bottom 0 0 -1 0 0 0 (1 -1 -1) 1 -2 PE 𝟏
𝟐=0.5
Right 0 1 0 2 2 2 (-1 -3 -3) -3 4 PL 𝟑
𝟒=0.75
Left 0 -1 0 0 0 0 (1 -1 -1) 1 -4 PE 𝟏
𝟒=0.25
Front 1 0 0 2 2 2 (-1 -3 -3) -1 -0.5 PE -2
Rear -1 0 0 0 0 0 (1 -1 -1) -1 0.5 PL 2.0
tPE=max(0.25, 0.5,-2)=0.50
D=p2-p1 =[0.5 3 1]-[1 -1 -1]=[-0.5 4 2] W1=(p1-f)=[1 -1 -1]-[2 2 2]=[-1 -3 -3]
If n.D>0 then PL else PE n D
w n p p n f p n t i i i i i i . . ) .( ) .( 1 2
1