Академический Документы
Профессиональный Документы
Культура Документы
Clipping
Point Clipping
clip
rectangle
y = ymax
(xmax, ymax)
x = xmin
(xmin, ymin)
x = xmax
y = ymin
xmin x xmax
ymin y ymax
Point Clipping
clip
rectangle
y = ymax
(xmax, ymax)
(x1, y1)
x = xmin
(xmin, ymin)
x = xmax
y = ymin
xmin x xmax
ymin y ymax
Line Clipping
clip
rectangle
Line Clipping
clip
rectangle
Line Clipping
D
D'
D'
C
clip
rectangle
Line Clipping
F
D
D'
D'
C
clip
rectangle
Line Clipping
F
D
D'
D'
C
E
H'
A
G'
clip
rectangle
H'
A
G'
Line Clipping
F
D
D'
D'
C
E
H'
A
G'
G'
J'
clip
rectangle
H'
A
G
I'
I
Line Clipping
Clipping Lines by Solving Simultaneous Equations
(x1, y1)
(x, y)
(x1, y1)
(xb, yb)
(xa, ya)
(xb, yb)
(x0, y0)
(x, y)
(xa, ya)
(x0, y0)
(xc, yc)
(xd, yd)
clip
rectangle
x x0 tline x1 x0 ,
x xa tedge xb xa ,
(xc, yc)
(xd, yd)
clip
rectangle
y y0 tline y1 y0
y ya tedge yb ya
Cohen-Sutherland Algorithm
The Cohen-Sutherland Line-Clipping
Algorithm performs initial tests on a line to
determine whether intersection calculations
can be avoided.
1.
2.
3.
Cohen-Sutherland Algorithm
1001
bit 0 : y ymax
bit 1 : y ymin
1000
1010
0001
0000
0010
0101
0100
0110
clip
rectangle
Region outcodes
bit 2 : x xmax
bit 3 : x xmin
Cohen-Sutherland Algorithm
1. A line segment can be trivially
accepted if the outcodes of both the
endpoints are zero.
2. A line segment can be trivially
rejected if the logical AND of the
outcodes of the endpoints is not zero.
3. A key property of the outcode is that
bits that are set in nonzero outcode
correspond to edges crossed.
Cohen-Sutherland Algorithm
E
D
clip
rectangle
B
A
An Example
Cohen-Sutherland Algorithm
E
D
clip
rectangle
An Example
Cohen-Sutherland Algorithm
D
clip
rectangle
An Example
Cohen-Sutherland Algorithm
clip
rectangle
An Example
Parametric Line-Clipping
(1) This fundamentally different (from CohenSutherland algorithm) and generally more
efficient algorithm was originally published by
Cyrus and Beck.
(2) Liang and Barsky later independently
developed a more efficient algorithm that is
especially fast in the special cases of upright
2D and 3D clipping regions.They also
introduced more efficient trivial rejection tests
for general clip regions.
PEi
Pi t PEi
P1
N i Pt PEi 0
P0
N i Pt PEi 0
N i Pt PEi 0
Ni
Line P0 P1 : Pt P0 P1 P0 t
N i Pt PEi 0
N P P P t P 0
N P P
t
N i P0 P1 P0 t PEi 0
i
Ei
Ei
N i P0 P1
N i P0 PEi
Ni D
, D P P
0
PEi
Pi t PEi
P1
N i Pt PEi 0
N i Pt PEi 0
P0
N i Pt PEi 0
Ni
N i P0 PEi
Ni D
t exists when
1
2
3
Ni 0
D 0 P0 P1
Ni D 0
Line 1
PE
P1
t=1
Line 2
P1
t=1
PL
PL
PL
P0
PE
t=0
PL
Line 3
P0
t=0
PE
PE
P0
t=0
PE = Potentially Entering
Clip
rectangle
PL = Potentially Leaving
N i D 0 PE
Ni D 0 PL
Angle 90
Angle 90
Polygon Clipping
Example
Polygon Clipping
Example
Polygon Clipping
Example
Sutherland-Hodgeman Algo.
Clip
Clip
ClipAgainst
Against
Against
TheBottom
Clipped
Right
Top
Left Clipping
Clipping
Clipping
Polygon
Boundary
Boundary
Boundary
Initial Condition
Outside
i:first output
p
s
Polygon
be ing
clippe d
p
s
s
p:output
(no output)
i:output
Clip
boundary
Case 4321
Algorithm
Input vertex P
No
First Point
Does SF
intersect E?
Yes
Yes
F=P
Does SP intersect
E?
Compute
Intersection I
No
Output
vertex I
Yes
Compute
Intersection Point
I
Exit
Output
vertex I
S=P
Yes
Is S on lef t
side of E?
Output
vertex S
NO
Exit
No
3D Clipping
Both the Cohen-Sutherland and Cyrus-Beck clipping algorithm
readily extend to 3D.
For Cohen-Sutherland algorithm use two extra-bit in outcode for
incorporating z < zmin and z > zmax regions
Thank You