Documentos de Académico
Documentos de Profesional
Documentos de Cultura
11 - Algoritmi de Decupare
11 - Algoritmi de Decupare
Decuparea capetelor
(Xmax , Ymax)
(Xmin , Ymin)
punct interior
acceptare
rejectare
intersectie
Rezolvarea ecuatiilor folosind y = mx + b ecuatia dreptei
1
Algoritmi de decupare
X = x0 + t(x1 x0)
Y = y0 + t(y1 y0)
0<t<1
B
A
A
segment inclus
segment disjunct
B
I2
B
I1
I1
A
segment intersectat
segment intersectat
ymin
xmin
xmax
4
ymax
D4
D1
D3
ymin
D3,D4 trebuie sa
se calculeze
punctele de
intersectie
D2
xmin
xmax
5
1001
Codificare b4b3b2b1
b4 = 1 y>ymax
b3 = 1 y<ymin
b2 = 1 x>xmax
0001
b1 = 1 x<xmin
0101
1000
1010
ymax
0000
0010
ymin
xmin
0100
0110
xmax
6
1001
1000
D3
1010
ymax
0001
D4
0101
xmin
0000
D1
0100
D5
0010
D2
0110
xmax
ymin
Segmentul P1P2
Se codifica P1, P2
c1 = codificare(P1)
c2 = codificare(P2)
If c1 = c2 = 0
acceptare triviala
If c1 & c2 = true
rejectare triviala
7
1001
1000
1010
ymax
0001
P1 0000
0010
ymin
0101
xmin
0100
P2
0110
xmax
9
1001
1000
1010
ymax
0001
P1 0000
0010
I1
0101
xmin
0100
ymin
0110
xmax
10
1001
1000
1010
ymax
P1
0001
0000
0010
ymin
0101
xmin
0100
P2
0110
xmax
11
1001
1000
1010
ymax
0001
I1
0000
0010
ymin
0101
xmin
0100
P2
0110
xmax
12
1001
1000
1010
ymax
0001
I1
0101
xmin
0000
I2
0100
0010
ymin
0110
xmax
13
15
16
17
1001
1000
P2
1010
ymax
0001
0101
xmin
0000
P1
0010
0100
0110
ymin
xmax
18
1001
1000
I1 1010
ymax
0001
0101
xmin
0000
P1
0010
0100
0110
ymin
xmax
19
1001
0001
0101
xmin
1000
I2
1010
ymax
0000
P1
0010
0100
0110
ymin
xmax
20
1000
1010
ymax
0001
0000
0010
ymin
0101
xmin
0100
0110
P2
xmax
21
1001 I1 1000
1010
ymax
0001
0000
0010
ymin
0101
xmin
0100
0110
P2
xmax
22
1001
0001
1000
I2
1010
0000
0010
ymax
ymin
0101
xmin
0100
0110
P2
xmax
23
1001
0001
1000
I2
1010
0000
I3 0010
ymax
ymin
0101
xmin
0100
0110
xmax
24
1001
1000
1010
ymax
0001
0000
0010
0101
0100
P1
0110
xmin
P2
ymin
xmax
25
1001
1000
1010
ymax
0001
0000
0010
I1
0101
xmin
0100
P2
ymin
0110
xmax
26
27
Ni 0
D 0 ( P1 P0)
Ni D 0 (Ei nu e paralela cu D)
28
I2
A
I1
D
I4
C
I3
P0 (t=0) P1 (t=1):
punct potential de intrare (Ni D < 0) PI
Punct potential de iesire (Ni D > 0) PE
30
PE
A
PI
D
PI
C
PE
PE
PI
A
PI
32
33
34
35
Algoritmul Liang-Barsky
36
Algoritmul Liang-Barsky>
Clasificarea punctelor de intersectie
punct potential de intrare (Ni D < 0) PI
Punct potential de iesire (Ni D > 0) PE
dx = x1-x0, dy = y1-y0
dx > 0 sau dy > 0 => PI
dx < 0 sau dy < 0 => PE
37
Algoritmul Liang-Barsky
bool Decupare_L(numitor, numarator, t_PI, t_PE)
{
//numitor = -(Ni.D): dx, -dx, dy, -dy
//numarator = Ni.(P1-PEi)
if(numitor > 0) //intersectie PI
{
calculeaza t = numarator/numitor;
if(t > t_PE) return FALSE;
if(t > t_PI) t_PI = t;
}
38
Algoritmul Liang-Barsky
if(numitor <0) //intersectie PE
{
calculeaza t = numarator/numitor;
if(t < t_PI) return FALSE;
39
Algoritmul Liang-Barsky
Decupare(x1,y1,x2,y2)
{
t_PI=0; t_PE = 1;
if (Decupare_L(dx, xmin-x1, t_PI, t_PE) == TRUE)//xmin
if (Decupare_L(-dx, x1-xmax, t_PI, t_PE) == TRUE)//xmax
if (Decupare_L(dy, ymin-xy, t_PI, t_PE) == TRUE)//ymin
if (Decupare_L(-dy, y1-ymax, t_PI, t_PE) == TRUE)//ymax
{
if(t_PE < 1)
{ x2 = x1 + t_PE*dx; y2 = y1 + t_PE * dy; }
if(t_PI > 0)
{ x1 = x1 + t_PI*dx; y1 = y1 + t_PI * dy; }
}
}
40
Decuparea poligoanelor
41
42
ext int
ext int
ext int
p
s
p
se pastreaza
nu se pastreaza
punctul de intersectie
nici un varf
I si varful p
s
se pastreaza
varful p
se pastreaza punctul
de intersectie I
43
44
45
46
47
48
49
50
51
52
53
Algoritmul Weiler-Atherton
Algoritmul Weiler-Atherton
In -> Out
Algoritmul Weiler-Atherton
Algoritmul Weiler-Atherton
Algoritmul Weiler-Atherton
Algoritmul Weiler-Atherton
Decuparea in 3D
60
bit 5
Near
bit 4
Top
bit 3
Bottom
bit 2
Right
bit 1
Left
61