HW 2D CGA - PPT 8 - Polygon Fill


Question
Solution:
First of all, we need to know the element to be inserted into SET and AEL. The element must contain ymax, x of ymin, dx, and dy. Also carry but only in AEL, carry doesn't need to be inserted into SET. With that said, let's begin with the first polygon.
Polygon 1
A(1, 6), B(5,4), C(3,1)
From these 3 vertices we need to find the edges element containing ymax, x of ymin, dx, and dy. Let's take a look at edge AB, the ymax is 6, the x of ymin is 5, the dx is 4, and the dy is -2. Now if we found dy<0 we need to make it positive, by multiplying dx and dy with -1, so we got dx = -4 and dy = 2. The same rule applies with edges BC and CA. After we've found all of the elements then, we put it into the SET just like below.
SET
yEdges
ymax6
5
4
AB
65-42
3
2
ymin1
BC
4323
CA
63-25

After finishing the SET, we can continue to the AEL. There are some rules to follow in calculating AEL as written below.
if dx<0 if dx>0
carry += dx
loop (carry ×(2)dy)
carry += dy
xofymin -= 1
carry += dx
loop (carry ×2dy)
carry -= dy
xofymin += 1

AEL
y=1
BC
43230
CA
63-250
y=2
0+2=2|×2|43
23=1
3+1=4
1|×2|2<3
0+(2)=2|×(2)|4<5
BC
4423-1
CA
63-25-2
y=3
1+2=1|×2|2<3
2+(2)=4|×(2)|85
4+5=1
31=2
1|×(2)|2<5
BC
44231
CA
62-251
y=4
BC has reached y=5 and AB starts 1+(2)=1|×(2)|2<5
AB
65-420
CA
62-25-1
y=5
0+(4)=4|×(2)|82
4+2=2
51=4
2|×(2)|42
2+2=0
41=3
0|×(2)|0<2
1+(2)=3|×(2)|65
3+5=2
21=1
2|×(2)|4<5
AB
63-420
CA
61-252
y=6 AB and CA both ended in y=6


Now let's continue to the second polygon.
Polygon 2
A(0, 0), B(5, 3), C(10, 0), D(5, 10)
 From these 4 vertices we need to find the edges element containing ymax, x of ymin, dx, and dy. Let's take a look at edge AB, the ymax is 3, the x of ymin is 0, the dx is 5, and the dy is 3. The same rule applies with edges BC, CD, and DA. After we've found all of the elements then, we put it into the SET just like below.
SET
yEdges
ymax10
9
8
7
6
5
4
3
2
1
ymin0
AB
3053
BC
310-53
CD
1010-510
DA
100510

Now for the AEL. Remember the rule for AEL? Here are the rules to follow in calculating AEL as written below.
if dx<0 if dx>0
carry += dx
loop (carry ×(2)dy)
carry += dy
xofymin -= 1
carry += dx
loop (carry ×2dy)
carry -= dy
xofymin += 1

AEL
y=0
AB
30530
BC
310-530
CD
1010-5100
DA
1005100
y=1
0+5=5
5|×2|103
53=2
0+1=1
2|×2|43
23=1
1+1=2
1|×2|2<3
0+(5)=5
5|×(2)|103
5+3=2
101=9
2|×(2)|43
2+3=1
91=8
1|×(2)|2<3
0+(5)=5
5|×(2)|1010
5+10=5
101=9
5|×(2)|10<10
0+5=5
5|×2|1010
510=5
0+1=1
5|×2|10<10
AB
3253-1
BC
38-531
CD
109-5105
DA
101510-5
y=2
1+5=4
4|×2|83
43=1
2+1=3
1|×2|2<3
1+(5)=4
4|×(2)|83
4+3=1
81=7
1|×(2)|2<3
5+(5)=0
0|×(2)|0<10
5+5=0
0|×2|0<10
AB
33531
BC
37-53-1
CD
109-5100
DA
1015100
y=3
AB popped BC popped 0+(5)=5
5|×(2)|1010
5+10=5
91=8
5|×(2)|10<10
0+5=5
5|×2|1010
510=5
1+1=2
5|×2|10<10
CD
108-5105
DA
102510-5
y=4
5+(5)=0
0|×(2)|0<10
5+5=0
0|×2|0<10
CD
108-5100
DA
1025100
y=5
0+(5)=5
5|×(2)|1010
5+10=5
81=7
5|×(2)|10<10
0+5=5
5|×2|1010
510=5
2+1=3
5|×2|10<10
CD
107-5105
DA
103510-5
y=6
5+(5)=0
0|×(2)|0<10
5+5=0
0|×2|0<10
CD
107-5100
DA
1035100
y=7
0+(5)=5
5|×(2)|1010
5+10=5
71=6
5|×(2)|10<10
0+5=5
5|×2|1010
510=5
3+1=4
5|×2|10<10
CD
106-5105
DA
104510-5
y=8
5+(5)=0
0|×(2)|0<10
5+5=0
0|×2|0<10
CD
106-5100
DA
1045100
y=9
0+(5)=5
5|×(2)|1010
5+10=5
61=5
5|×(2)|10<10
0+5=5
5|×2|1010
510=5
4+1=5
5|×2|10<10
CD
105-5105
DA
105510-5
y=10
CD popped DA popped

Now for the third polygon.
Polygon 3
A(7, 1), B(13, 5), C(13, 11), D(7, 7), E(2, 9), F(2, 3)
From these 6 vertices we need to find the edges element containing ymax, x of ymin, dx, and dy. Let's take a look at edge AB, the ymax is 5, the x of ymin is 7, the dx is 6, and the dy is 4. The same rule applies with edges BC, CD, DE, EF, and FA. After we've found all of the elements then, we put it into the SET just like below.
SET
yEdges
ymax11
10
9
8
7
CD
11764
DE
97-52
6
5
BC
111306
4
3
EF
9206
2
ymin1
AB
5764
FA
37-52
Now for the AEL. Remember the rule for AEL? Here are the rules to follow in calculating AEL as written below.
if dx<0 if dx>0
carry += dx
loop (carry ×(2)dy)
carry += dy
xofymin -= 1
carry += dx
loop (carry ×2dy)
carry -= dy
xofymin += 1

AEL
y=1
AB
57640
FA
37-520
y=2
0+6=6
6|×2|124
64=2
7+1=8
2|×2|44
24=2
8+1=9
2|×2|4<4

05=5
5|×(2)|102
5+2=3
71=6
3|×(2)|62
3+2=1
61=5
1|×(2)|22
1+2=1
51=4
1|×(2)|2<2

AB
5964-2
FA
34-521
y=3
2+6=4
4|×2|84
44=0
9+1=10
0|×2|0<4

FA popped, insert EF
AB
510640
EF
92060
y=4
0+6=6
6|×2|124
64=2
10+1=11
2|×2|44
24=2
11+1=12
2|×2|4<4

EF dx=0 so no need
to calculate this one
AB
51264-2
EF
92060
y=5
EF dx=0 so no need
to calculate this one
AB popped, insert BC
EF
92060
BC
1113060
y=6
EF dx=0 so no need
to calculate this one
BC dx=0 so no need
to calculate this one
EF
92060
BC
1113060
y=7
EF dx=0 so no need
to calculate this one
BC dx=0 so no need
to calculate this one
insert CD insert DE
EF
92060
BC
1113060
CD
117640
DE
97-520
y=8
EF dx=0 so no need
to calculate this one
BC dx=0 so no need
to calculate this one
0+6=6
6|×2|124
64=2
7+1=8
2|×2|64
24=2
8+1=9
2|×2|4<4

05=5
5|×(2)|102
5+2=3
71=6
3|×(2)|62
3+2=1
61=5
1|×(2)|22
1+2=1
51=4
1|×(2)|2<2

EF
92060
BC
1113060
CD
11964-2
DE
94-521
y=9
EF popped BC dx=0 so no need
to calculate this one
2+6=4
4|×2|104
44=0
9+1=10
0|×2|0<4

DE popped
BC
1113060
CD
1110640
y=10
BC dx=0 so no need
to calculate this one
0+6=6
6|×2|124
64=2
10+1=11
2|×2|44
24=2
11+1=12
2|×2|4<4

BC
1113060
CD
111264-2
y=11
BC popped CD popped

Now let's continue to the fourth polygon.
Polygon 4
A(3, 3), B(10, 5), C(14, 5), D(8, 1), E(21, 10), F(13, 10), G(3, 17)
From these 7 vertices we need to find the edges element containing ymax, x of ymin, dx, and dy. Let's take a look at edge AB, the ymax is 5, the x of ymin is 3, the dx is 7, and the dy is 2. The same rule applies with edges BC, CD, DE, EF, FG, and GA. After we've found all of the elements then, we put it into the SET just like below.
SET
yEdges
ymax17
16
15
14
13
12
11
10
FG
1713-107
9
8
7
6
5
4
3
AB
5372
GA
173014
2
ymin1
CD
518-44
DE
101839
Notice that out of 7 pairs of edges we only insert 5 of them, that is because we don't need to include horizontal edges where dy=0 such as BC and EF. Now for the AEL. Remember the rule for AEL? Here are the rules to follow in calculating AEL as written below.
if dx<0 if dx>0
carry += dx
loop (carry ×(2)dy)
carry += dy
xofymin -= 1
carry += dx
loop (carry ×2dy)
carry -= dy
xofymin += 1
AEL
y=1
CD
5 18 -4 4 0
DE
10 18 3 9 0
y=2
04=4
4|×(2)|84
4+4=0
181=17
0|×(2)|0<4

0+3=3
3|×2|6<9

CD
5 17 -4 4 0
DE
10 18 3 9 3
y=3
04=4
4|×(2)|84
4+4=0
171=16
0|×(2)|0<4

3+3=6
6|×2|129
69=3
18+1=19
3|×2|6<9

insert AB insert GA
CD
5 16 -4 4 0
DE
10 19 3 9 -3
AB
5 3 7 2 0
GA
17 3 0 14 0
y=4
04=4
4|×(2)|84
4+4=0
161=15
0|×(2)|0<4

3+3=0
0|×2|0<9

0+7=7
7|×2|142
72=5
3+1=4
5|×2|102
52=3
4+1=5
3|×2|62
32=1
5+1=6
1|×2|22
12=1
6+1=7
1|×2|2<2

GA dx=0 so no need
to calculate this one
CD
5 15 -4 4 0
DE
10 19 3 9 0
AB
5 7 7 2 -1
GA
17 3 0 14 0
y=5
CD popped 0+3=3
3|×2|3<9

AB popped GA dx=0 so no need
to calculate this one
DE
10 19 3 9 3
GA
17 3 0 14 0
y=6
3+3=6
6|×2|129
69=3
19+1=20
3|×2|6<9

GA dx=0 so no need
to calculate this one
DE
10 20 3 9 -3
GA
17 3 0 14 0
y=7
3+3=0
0|×2|0<9

GA dx=0 so no need
to calculate this one
DE
10 20 3 9 0
GA
17 3 0 14 0
y=8
0+3=3
3|×2|6<9

GA dx=0 so no need
to calculate this one
DE
10 20 3 9 3
GA
17 3 0 14 0
y=9
3+3=6
6|×2|129
69=3
20+1=21
3|×2|6<9

GA dx=0 so no need
to calculate this one
DE
10 21 3 9 -3
GA
17 3 0 14 0
y=10
DE popped, insert FG GA dx=0 so no need
to calculate this one
FG
17 13 -10 7 0
GA
17 3 0 14 0
y=11
010=10
10|×(2)|207
10+7=3
131=12
3|×(2)|6<7

GA dx=0 so no need
to calculate this one
FG
17 12 -10 7 -3
GA
17 3 0 14 0
y=12
310=13
13|×(2)|267
13+7=6
121=11
6|×(2)|127
6+7=1
111=10
1|×(2)|2<7

GA dx=0 so no need
to calculate this one
FG
17 10 -10 7 1
GA
17 3 0 14 0
y=13
110=9
9|×(2)|187
9+7=2
101=9
2|×(2)|4<7

GA dx=0 so no need
to calculate this one
FG
17 9 -10 7 -2
GA
17 3 0 14 0
y=14
210=12
12|×(2)|247
12+7=5
91=8
5|×(2)|107
5+7=2
81=7
2|×(2)|2<7

GA dx=0 so no need
to calculate this one
FG
17 7 -10 7 2
GA
17 3 0 14 0
y=15
210=8
8|×(2)|167
8+7=1
71=6
1|×(2)|2<7

GA dx=0 so no need
to calculate this one
FG
17 6 -10 7 -1
GA
17 3 0 14 0
y=16
110=11
11|×(2)|227
11+7=4
61=5
4|×(2)|87
4+7=3
51=4
3|×(2)|6<7

GA dx=0 so no need
to calculate this one
FG
17 4 -10 7 3
GA
17 3 0 14 0
y=17
FG popped GA popped

And that's that is all the solution for this question.

Comments

Post a Comment

Popular posts from this blog

2D CGA - Midtest 2014