-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTPolygon.java
More file actions
217 lines (195 loc) · 4.53 KB
/
Copy pathTPolygon.java
File metadata and controls
217 lines (195 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// edge class
//
// provides the polygons for the QTM
//
import java.util.*;
public class TPolygon
{
// components of a polygon
// sub polygons
private TPolygon _Poly1;
private TPolygon _Poly2;
private TPolygon _Poly3;
private TPolygon _Poly4;
// Edges
private TEdge _Edge1;
private TEdge _Edge2;
private TEdge _Edge3;
// Constructor
public TPolygon (TEdge Edge1, TEdge Edge2, TEdge Edge3)
{
// set up the polygon
_Edge1 = Edge1;
_Edge2 = Edge2;
_Edge3 = Edge3;
// null the sub polygons
_Poly1 = null;
_Poly2 = null;
_Poly3 = null;
_Poly4 = null;
}
private boolean IsSubdivided()
{
if (_Poly1 == null)
{
return false;
}
else
{
return true;
}
}
private void Subdivide()
{
// subdivide the edges
_Edge1.Subdivide();
_Edge2.Subdivide();
_Edge3.Subdivide();
// get the sub edges
TEdge E1 = _Edge1.Edge1();
TEdge E2 = _Edge1.Edge2();
TEdge E3 = _Edge2.Edge1();
TEdge E4 = _Edge2.Edge2();
TEdge E5 = _Edge3.Edge1();
TEdge E6 = _Edge3.Edge2();
// make the other three subedges
TEdge E7 = new TEdge(_Edge1.Edge1().BottomEnd(), _Edge2.Edge1().BottomEnd(), E1.Seed(), E1.SD());
TEdge E8 = new TEdge(_Edge1.Edge1().BottomEnd(), _Edge3.Edge1().BottomEnd(), E1.Seed(), E1.SD());
TEdge E9 = new TEdge(_Edge2.Edge1().BottomEnd(), _Edge3.Edge1().BottomEnd(), E1.Seed(), E1.SD());
// make the center polygon
_Poly4 = new TPolygon(E7, E8, E9);
// work out which way around the data is
// get the six vertices
TVector3d A1 = _Edge1.TopEnd().Position();
TVector3d A2 = _Edge1.BottomEnd().Position();
TVector3d B1 = _Edge2.TopEnd().Position();
TVector3d B2 = _Edge2.BottomEnd().Position();
TVector3d C1 = _Edge3.TopEnd().Position();
TVector3d C2 = _Edge3.BottomEnd().Position();
// now find out which order they go in
if (A1.IsEqual(B1))
{
if (A2.IsEqual(C1))
{
// create polygon
_Poly1 = new TPolygon(E7, E3, E1);
_Poly2 = new TPolygon(E5, E8, E2);
_Poly3 = new TPolygon(E4, E9, E6);
}
else
{
// create polygon
_Poly1 = new TPolygon(E7, E3, E1);
_Poly2 = new TPolygon(E6, E8, E2);
_Poly3 = new TPolygon(E4, E9, E5);
}
}
else if (A1.IsEqual(B2))
{
if (A2.IsEqual(C1))
{
// create polygon
_Poly1 = new TPolygon(E7, E4, E1);
_Poly2 = new TPolygon(E5, E8, E2);
_Poly3 = new TPolygon(E3, E9, E6);
}
else
{
// create polygon
_Poly1 = new TPolygon(E7, E4, E1);
_Poly2 = new TPolygon(E6, E8, E2);
_Poly3 = new TPolygon(E3, E9, E5);
}
}
else if (A2.IsEqual(B1))
{
if (A1.IsEqual(C1))
{
// create polygon
_Poly1 = new TPolygon(E7, E3, E2);
_Poly2 = new TPolygon(E5, E8, E1);
_Poly3 = new TPolygon(E4, E9, E6);
}
else
{
// create polygon
_Poly1 = new TPolygon(E7, E3, E2);
_Poly2 = new TPolygon(E6, E8, E1);
_Poly3 = new TPolygon(E4, E9, E5);
}
}
else
{
if (A1.IsEqual(C1))
{
// create polygon
_Poly1 = new TPolygon(E7, E4, E2);
_Poly2 = new TPolygon(E5, E8, E1);
_Poly3 = new TPolygon(E3, E9, E6);
}
else
{
// create polygon
_Poly1 = new TPolygon(E7, E4, E2);
_Poly2 = new TPolygon(E6, E8, E1);
_Poly3 = new TPolygon(E3, E9, E5);
}
}
}
public void Generate(int Level, Vector Points)
{
if (Level == 0)
{
// use this level of the QTM
// work out which way around the data is
// get the six vertices
TVector3d A1 = _Edge1.TopEnd().Position();
TVector3d A2 = _Edge1.BottomEnd().Position();
TVector3d B1 = _Edge2.TopEnd().Position();
TVector3d B2 = _Edge2.BottomEnd().Position();
// now find out which order they go in
if (A1.IsEqual(B1))
{
// create polygon
Points.addElement(A2);
Points.addElement(A1);
Points.addElement(B2);
}
else if (A1.IsEqual(B2))
{
// create polygon
Points.addElement(A2);
Points.addElement(A1);
Points.addElement(B1);
}
else if (A2.IsEqual(B1))
{
// create polygon
Points.addElement(A1);
Points.addElement(A2);
Points.addElement(B2);
}
else
{
// create polygon
Points.addElement(A1);
Points.addElement(A2);
Points.addElement(B1);
}
}
else
{
// check to see if the polygon is subdivided
if (this.IsSubdivided() == false)
{
// subdivide the polygon
this.Subdivide();
}
// call the child polygons
_Poly1.Generate(Level - 1, Points);
_Poly2.Generate(Level - 1, Points);
_Poly3.Generate(Level - 1, Points);
_Poly4.Generate(Level - 1, Points);
}
}
}