ccm commited on
Commit
327238b
·
1 Parent(s): 1011d70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1075 -3
app.py CHANGED
@@ -2,12 +2,1087 @@
2
  import keras
3
  # For random calculations
4
  import numpy
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Disable eager execution because its bad
7
  from tensorflow.python.framework.ops import disable_eager_execution
8
  disable_eager_execution()
9
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  # This function loads a fuckton of data
12
  def load_data():
13
  # Open all the files we downloaded at the beginning and take out hte good bits
@@ -31,9 +1106,6 @@ def load_data():
31
 
32
  # Return good bits to user
33
  return curves, geometry, S, N, D, F, G, new_curves, new_geometry
34
-
35
- import gradio
36
- import pandas
37
 
38
  curves, geometry, S, N, D, F, G, new_curves, new_geometry = load_data()
39
 
 
2
  import keras
3
  # For random calculations
4
  import numpy
5
+
6
+ import gradio
7
+ import pandas
8
+
9
+
10
+ # New for geometry creation
11
+ import glob
12
+ import os
13
+ import shutil
14
+ import stat
15
+ import math
16
+ import platform
17
+ import scipy.spatial
18
 
19
  # Disable eager execution because its bad
20
  from tensorflow.python.framework.ops import disable_eager_execution
21
  disable_eager_execution()
22
 
23
 
24
+ # Big bunch of geometry stuff
25
+ import glob
26
+ import os
27
+ import shutil
28
+ import stat
29
+ import math
30
+ import platform
31
+ import scipy.spatial
32
+
33
+ class Mesh:
34
+ def __init__(self):
35
+ # Define blank values
36
+ self.np = 0
37
+ self.nf = 0
38
+ self.X = []
39
+ self.Y = []
40
+ self.Z = []
41
+ self.P = []
42
+
43
+ def combine_meshes(self, ob1, ob2):
44
+ # Check for largest mesh
45
+ if ob1.nf < ob2.nf:
46
+ coin_test = ob1.make_coin()
47
+ coin_target = ob2.make_coin()
48
+ else:
49
+ coin_test = ob2.make_coin()
50
+ coin_target = ob1.make_coin()
51
+ # Check for duplicate panels
52
+ deletion_list = []
53
+ for iF in range(numpy.size(coin_test[1, 1, :])):
54
+ panel_test = coin_test[:, :, iF]
55
+ for iFF in range(numpy.size(coin_target[1, 1, :])):
56
+ panel_target = coin_target[:, :, iFF]
57
+ if numpy.sum(panel_test == panel_target) == 12:
58
+ coin_target = numpy.delete(coin_target, iFF, 2)
59
+ deletion_list.append(iF)
60
+ coin_test = numpy.delete(coin_test, deletion_list, 2)
61
+
62
+ # Concatenate unique meshes
63
+ coin = numpy.concatenate((coin_test, coin_target), axis=2)
64
+ self.np = numpy.size(coin[1, 1, :]) * 4
65
+ self.nf = numpy.size(coin[1, 1, :])
66
+ self.X = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
67
+ self.Y = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
68
+ self.Z = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
69
+ self.P = numpy.zeros((numpy.size(coin[1, 1, :]), 4), dtype=int)
70
+
71
+ iP = 0
72
+ for iF in range(numpy.size(coin[1, 1, :])):
73
+ for iC in range(4):
74
+ self.X[iP] = coin[0, iC, iF]
75
+ self.Y[iP] = coin[1, iC, iF]
76
+ self.Z[iP] = coin[2, iC, iF]
77
+ iP += 1
78
+ self.P[iF, 0] = 1 + iF * 4
79
+ self.P[iF, 1] = 2 + iF * 4
80
+ self.P[iF, 2] = 3 + iF * 4
81
+ self.P[iF, 3] = 4 + iF * 4
82
+
83
+ def make_coin(self):
84
+ coin = numpy.zeros((3, 4, self.nf))
85
+ for iF in range(self.nf):
86
+ for iC in range(4):
87
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
88
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
89
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
90
+ return coin
91
+
92
+ def delete_horizontal_panels(self):
93
+ coin = self.make_coin()
94
+ apex = numpy.min(self.Z)
95
+ zLoc = numpy.zeros(4)
96
+ deletion_list = []
97
+
98
+ # Check every panel for horizontality and higher position than lowest point
99
+ for iP in range(self.nf):
100
+ for iC in range(4):
101
+ zLoc[iC] = coin[2, iC, iP]
102
+ if numpy.abs(numpy.mean(zLoc) - zLoc[0]) < 0.001 and numpy.mean(zLoc) > apex:
103
+ deletion_list.append(iP)
104
+
105
+ # Delete selected panels
106
+ coin = numpy.delete(coin, deletion_list, 2)
107
+
108
+ # Remake mesh
109
+ self.np = numpy.size(coin[1, 1, :]) * 4
110
+ self.nf = numpy.size(coin[1, 1, :])
111
+ self.X = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
112
+ self.Y = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
113
+ self.Z = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
114
+ self.P = numpy.zeros((numpy.size(coin[1, 1, :]), 4), dtype=int)
115
+
116
+ iP = 0
117
+ for iF in range(numpy.size(coin[1, 1, :])):
118
+ for iC in range(4):
119
+ self.X[iP] = coin[0, iC, iF]
120
+ self.Y[iP] = coin[1, iC, iF]
121
+ self.Z[iP] = coin[2, iC, iF]
122
+ iP += 1
123
+ self.P[iF, 0] = 1 + (iF) * 4
124
+ self.P[iF, 1] = 2 + (iF) * 4
125
+ self.P[iF, 2] = 3 + (iF) * 4
126
+ self.P[iF, 3] = 4 + (iF) * 4
127
+
128
+
129
+
130
+
131
+ def writeMesh(msh, filename):
132
+ with open(filename, 'w') as f:
133
+ f.write('{:d}\n'.format(msh.np))
134
+ f.write('{:d}\n'.format(msh.nf))
135
+ for iP in range(msh.np):
136
+ f.write(' {:.7f} {:.7f} {:.7f}\n'.format(msh.X[iP], msh.Y[iP], msh.Z[iP]))
137
+ for iF in range(msh.nf):
138
+ f.write(' {:d} {:d} {:d} {:d}\n'.format(msh.P[iF, 0], msh.P[iF, 1], msh.P[iF, 2], msh.P[iF, 3]))
139
+ return None
140
+
141
+
142
+
143
+ class box:
144
+ def __init__(self, length, width, height, cCor):
145
+ self.length = length
146
+ self.width = width
147
+ self.height = height
148
+ self.xC = cCor[0]
149
+ self.yC = cCor[1]
150
+ self.zC = cCor[2]
151
+ self.name = 'box'
152
+ self.panelize()
153
+ self.translate(self.xC, self.yC, self.zC)
154
+
155
+ def panelize(self):
156
+ self.nf = 6
157
+ self.np = 8
158
+ self.X = numpy.array(
159
+ [-self.length / 2.0, self.length / 2.0, -self.length / 2.0, self.length / 2.0, -self.length / 2.0,
160
+ self.length / 2.0, -self.length / 2.0, self.length / 2.0])
161
+ self.Y = numpy.array([self.width / 2.0, self.width / 2.0, self.width / 2.0, self.width / 2.0, -self.width / 2.0,
162
+ -self.width / 2.0, -self.width / 2.0, -self.width / 2.0])
163
+ self.Z = numpy.array(
164
+ [-self.height / 2.0, -self.height / 2.0, self.height / 2.0, self.height / 2.0, -self.height / 2.0,
165
+ -self.height / 2.0, self.height / 2.0, self.height / 2.0])
166
+ self.P = numpy.zeros([6, 4], dtype=int)
167
+ self.P[0, :] = numpy.array([3, 4, 2, 1])
168
+ self.P[1, :] = numpy.array([4, 8, 6, 2])
169
+ self.P[2, :] = numpy.array([8, 7, 5, 6])
170
+ self.P[3, :] = numpy.array([7, 3, 1, 5])
171
+ self.P[4, :] = numpy.array([2, 6, 5, 1])
172
+ self.P[5, :] = numpy.array([8, 4, 3, 7])
173
+ # Define triangles for plotting
174
+ self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
175
+ iT = 0
176
+ for iTr in range(self.nf):
177
+ self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
178
+ self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
179
+ iT += 2
180
+
181
+ def translate(self, xT, yT, zT):
182
+ self.X += xT
183
+ self.Y += yT
184
+ self.Z += zT
185
+
186
+ def rotate(self, a1, a2, theta):
187
+ R = numpy.zeros([3, 3])
188
+ # Normal vector through origin
189
+ u = a2[0] - a1[0]
190
+ v = a2[1] - a1[1]
191
+ w = a2[2] - a1[2]
192
+ u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
193
+ v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
194
+ w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
195
+ # Translate mesh so that rotation axis starts from the origin
196
+ self.X -= a1[0]
197
+ self.Y -= a1[1]
198
+ self.Z -= a1[2]
199
+
200
+ # Rotation matrix
201
+ R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
202
+ R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
203
+ R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
204
+ R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
205
+ R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
206
+ R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
207
+ R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
208
+ R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
209
+ R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
210
+
211
+ for iP in range(self.np):
212
+ p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
213
+ p2 = numpy.dot(R, p1)
214
+ self.X[iP] = p2[0]
215
+ self.Y[iP] = p2[1]
216
+ self.Z[iP] = p2[2]
217
+
218
+ # Translate back to original position
219
+
220
+ self.X += a1[0]
221
+ self.Y += a1[1]
222
+ self.Z += a1[2]
223
+
224
+ def makeCoin(self):
225
+ coin = numpy.zeros((3, 4, self.nf))
226
+ for iF in range(self.nf):
227
+ for iC in range(4):
228
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
229
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
230
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
231
+ return coin
232
+
233
+
234
+
235
+
236
+ class cone:
237
+ def __init__(self, diameter, height, cCor):
238
+ self.diameter = diameter
239
+ self.height = height
240
+ self.xC = cCor[0]
241
+ self.yC = cCor[1]
242
+ self.zC = cCor[2]
243
+ self.name = 'cone'
244
+ self.panelize()
245
+ self.translate(self.xC, self.yC, self.zC)
246
+
247
+ def panelize(self):
248
+ Ntheta = 18
249
+ Nz = 3
250
+ theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
251
+ self.nf = 0
252
+ self.np = 0
253
+ r = [0, self.diameter / 2.0, 0]
254
+ z = [0, 0, -self.height]
255
+ self.X = []
256
+ self.Y = []
257
+ self.Z = []
258
+ self.P = numpy.zeros([(len(r) - 1) * (Ntheta - 1), 4], dtype=int)
259
+ n = len(r)
260
+
261
+ for iT in range(Ntheta):
262
+ for iN in range(n):
263
+ self.X.append(r[iN] * numpy.cos(theta[iT]))
264
+ self.Y.append(r[iN] * numpy.sin(theta[iT]))
265
+ self.Z.append(z[iN])
266
+ self.np += 1
267
+
268
+ iP = 0
269
+ for iN in range(1, n):
270
+ for iT in range(1, Ntheta):
271
+ self.P[iP, 0] = iN + n * (iT - 1)
272
+ self.P[iP, 1] = iN + 1 + n * (iT - 1)
273
+ self.P[iP, 2] = iN + 1 + n * iT
274
+ self.P[iP, 3] = iN + n * iT
275
+ self.nf += 1
276
+ iP += 1
277
+
278
+ self.X = numpy.array(self.X)
279
+ self.Y = numpy.array(self.Y)
280
+ self.Z = numpy.array(self.Z)
281
+ # Define triangles for plotting
282
+ self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
283
+ iT = 0
284
+ for iTr in range(self.nf):
285
+ self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
286
+ self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
287
+ iT += 2
288
+
289
+ def translate(self, xT, yT, zT):
290
+ self.X += xT
291
+ self.Y += yT
292
+ self.Z += zT
293
+
294
+ def rotate(self, a1, a2, theta):
295
+ R = numpy.zeros([3, 3])
296
+ # Normal vector through origin
297
+ u = a2[0] - a1[0]
298
+ v = a2[1] - a1[1]
299
+ w = a2[2] - a1[2]
300
+ u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
301
+ v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
302
+ w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
303
+ # Translate mesh so that rotation axis starts from the origin
304
+ self.X -= a1[0]
305
+ self.Y -= a1[1]
306
+ self.Z -= a1[2]
307
+
308
+ # Rotation matrix
309
+ R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
310
+ R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
311
+ R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
312
+ R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
313
+ R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
314
+ R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
315
+ R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
316
+ R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
317
+ R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
318
+
319
+ for iP in range(self.np):
320
+ p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
321
+ p2 = numpy.dot(R, p1)
322
+ self.X[iP] = p2[0]
323
+ self.Y[iP] = p2[1]
324
+ self.Z[iP] = p2[2]
325
+
326
+ # Translate back to original position
327
+
328
+ self.X += a1[0]
329
+ self.Y += a1[1]
330
+ self.Z += a1[2]
331
+
332
+ def makeCoin(self):
333
+ coin = numpy.zeros((3, 4, self.nf))
334
+ for iF in range(self.nf):
335
+ for iC in range(4):
336
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
337
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
338
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
339
+ return coin
340
+
341
+
342
+
343
+ class cylinder:
344
+ def __init__(self, diameter, height, cCor):
345
+ self.diameter = diameter
346
+ self.height = height
347
+ self.xC = cCor[0]
348
+ self.yC = cCor[1]
349
+ self.zC = cCor[2]
350
+ self.name = 'cylinder'
351
+ self.panelize()
352
+ self.translate(self.xC, self.yC, self.zC)
353
+
354
+ def panelize(self):
355
+ Ntheta = 18
356
+ Nz = 3
357
+ theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
358
+ self.nf = 0
359
+ self.np = 0
360
+ r = [0, self.diameter / 2.0, self.diameter / 2.0, 0]
361
+ z = [0, 0, -self.height, -self.height]
362
+ self.X = []
363
+ self.Y = []
364
+ self.Z = []
365
+ self.P = numpy.zeros([(len(r) - 1) * (Ntheta - 1), 4], dtype=int)
366
+ n = len(r)
367
+
368
+ for iT in range(Ntheta):
369
+ for iN in range(n):
370
+ self.X.append(r[iN] * numpy.cos(theta[iT]))
371
+ self.Y.append(r[iN] * numpy.sin(theta[iT]))
372
+ self.Z.append(z[iN])
373
+ self.np += 1
374
+
375
+ iP = 0
376
+ for iN in range(1, n):
377
+ for iT in range(1, Ntheta):
378
+ self.P[iP, 0] = iN + n * (iT - 1)
379
+ self.P[iP, 1] = iN + 1 + n * (iT - 1)
380
+ self.P[iP, 2] = iN + 1 + n * iT
381
+ self.P[iP, 3] = iN + n * iT
382
+ self.nf += 1
383
+ iP += 1
384
+
385
+ self.X = numpy.array(self.X)
386
+ self.Y = numpy.array(self.Y)
387
+ self.Z = numpy.array(self.Z)
388
+ # Define triangles for plotting
389
+ self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
390
+ iT = 0
391
+ for iTr in range(self.nf):
392
+ self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
393
+ self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
394
+ iT += 2
395
+
396
+ def translate(self, xT, yT, zT):
397
+ self.X += xT
398
+ self.Y += yT
399
+ self.Z += zT
400
+
401
+ def rotate(self, a1, a2, theta):
402
+ R = numpy.zeros([3, 3])
403
+ # Normal vector through origin
404
+ u = a2[0] - a1[0]
405
+ v = a2[1] - a1[1]
406
+ w = a2[2] - a1[2]
407
+ u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
408
+ v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
409
+ w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
410
+ # Translate mesh so that rotation axis starts from the origin
411
+ self.X -= a1[0]
412
+ self.Y -= a1[1]
413
+ self.Z -= a1[2]
414
+
415
+ # Rotation matrix
416
+ R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
417
+ R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
418
+ R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
419
+ R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
420
+ R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
421
+ R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
422
+ R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
423
+ R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
424
+ R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
425
+
426
+ for iP in range(self.np):
427
+ p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
428
+ p2 = numpy.dot(R, p1)
429
+ self.X[iP] = p2[0]
430
+ self.Y[iP] = p2[1]
431
+ self.Z[iP] = p2[2]
432
+
433
+ # Translate back to original position
434
+
435
+ self.X += a1[0]
436
+ self.Y += a1[1]
437
+ self.Z += a1[2]
438
+
439
+ def makeCoin(self):
440
+ coin = numpy.zeros((3, 4, self.nf))
441
+ for iF in range(self.nf):
442
+ for iC in range(4):
443
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
444
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
445
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
446
+ return coin
447
+
448
+
449
+
450
+
451
+ class hemicylinder:
452
+ def __init__(self, diameter, height, cCor):
453
+ self.diameter = diameter
454
+ self.height = height
455
+ self.xC = cCor[0]
456
+ self.yC = cCor[1]
457
+ self.zC = cCor[2]
458
+ self.name = 'hemicylinder'
459
+ self.panelize()
460
+ self.translate(self.xC, self.yC, self.zC)
461
+
462
+ def panelize(self):
463
+ Ntheta = 18
464
+ Nz = 3
465
+ theta = [xx * numpy.pi / (Ntheta - 1) - numpy.pi / 2.0 for xx in range(Ntheta)]
466
+ self.nf = 0
467
+ self.np = 0
468
+ r = [0, self.diameter / 2.0, self.diameter / 2.0, 0]
469
+ z = [self.height / 2.0, self.height / 2.0, -self.height / 2.0, -self.height / 2.0]
470
+ self.X = []
471
+ self.Y = []
472
+ self.Z = []
473
+ self.P = numpy.zeros([(len(r) - 1) * (Ntheta - 1), 4], dtype=int)
474
+ n = len(r)
475
+
476
+ for iT in range(Ntheta):
477
+ for iN in range(n):
478
+ self.Z.append(-r[iN] * numpy.cos(theta[iT]))
479
+ self.X.append(r[iN] * numpy.sin(theta[iT]))
480
+ self.Y.append(z[iN])
481
+ self.np += 1
482
+
483
+ iP = 0
484
+ for iN in range(1, n):
485
+ for iT in range(1, Ntheta):
486
+ self.P[iP, 3] = iN + n * (iT - 1)
487
+ self.P[iP, 2] = iN + 1 + n * (iT - 1)
488
+ self.P[iP, 1] = iN + 1 + n * iT
489
+ self.P[iP, 0] = iN + n * iT
490
+ self.nf += 1
491
+ iP += 1
492
+
493
+ self.X = numpy.array(self.X)
494
+ self.Y = numpy.array(self.Y)
495
+ self.Z = numpy.array(self.Z)
496
+ # Define triangles for plotting
497
+ self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
498
+ iT = 0
499
+ for iTr in range(self.nf):
500
+ self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
501
+ self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
502
+ iT += 2
503
+
504
+ def translate(self, xT, yT, zT):
505
+ self.X += xT
506
+ self.Y += yT
507
+ self.Z += zT
508
+
509
+ def rotate(self, a1, a2, theta):
510
+ R = numpy.zeros([3, 3])
511
+ # Normal vector through origin
512
+ u = a2[0] - a1[0]
513
+ v = a2[1] - a1[1]
514
+ w = a2[2] - a1[2]
515
+ u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
516
+ v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
517
+ w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
518
+ # Translate mesh so that rotation axis starts from the origin
519
+ self.X -= a1[0]
520
+ self.Y -= a1[1]
521
+ self.Z -= a1[2]
522
+
523
+ # Rotation matrix
524
+ R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
525
+ R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
526
+ R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
527
+ R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
528
+ R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
529
+ R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
530
+ R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
531
+ R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
532
+ R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
533
+
534
+ for iP in range(self.np):
535
+ p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
536
+ p2 = numpy.dot(R, p1)
537
+ self.X[iP] = p2[0]
538
+ self.Y[iP] = p2[1]
539
+ self.Z[iP] = p2[2]
540
+
541
+ # Translate back to original position
542
+
543
+ self.X += a1[0]
544
+ self.Y += a1[1]
545
+ self.Z += a1[2]
546
+
547
+ def makeCoin(self):
548
+ coin = numpy.zeros((3, 4, self.nf))
549
+ for iF in range(self.nf):
550
+ for iC in range(4):
551
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
552
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
553
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
554
+ return coin
555
+
556
+
557
+ class sphere:
558
+ def __init__(self, diameter, cCor):
559
+ self.diameter = diameter
560
+ self.xC = cCor[0]
561
+ self.yC = cCor[1]
562
+ self.zC = cCor[2]
563
+ self.name = 'sphere'
564
+ self.panelize()
565
+ self.translate(self.xC, self.yC, self.zC)
566
+
567
+ def panelize(self):
568
+ Ntheta = 18
569
+ Nthetad2 = int(Ntheta / 2)
570
+ Nz = 3
571
+ theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
572
+ phi = [xx * numpy.pi / (Ntheta / 2 - 1) for xx in range(Nthetad2)]
573
+ self.nf = 0
574
+ self.np = 0
575
+ r = self.diameter / 2.0
576
+ self.X = []
577
+ self.Y = []
578
+ self.Z = []
579
+ self.P = numpy.zeros([(Ntheta - 1) * (Nthetad2 - 1), 4], dtype=int)
580
+
581
+ for iT in range(Nthetad2):
582
+ for iTT in range(Ntheta):
583
+ self.X.append(r * numpy.cos(theta[iTT]) * numpy.sin(phi[iT]))
584
+ self.Y.append(r * numpy.sin(theta[iTT]) * numpy.sin(phi[iT]))
585
+ self.Z.append(r * numpy.cos(phi[iT]))
586
+ self.np += 1
587
+
588
+ iP = 0
589
+ for iN in range(1, Ntheta):
590
+ for iT in range(1, Nthetad2):
591
+ self.P[iP, 3] = iN + Ntheta * (iT - 1)
592
+ self.P[iP, 2] = iN + 1 + Ntheta * (iT - 1)
593
+ self.P[iP, 1] = iN + 1 + Ntheta * iT
594
+ self.P[iP, 0] = iN + Ntheta * iT
595
+ self.nf += 1
596
+ iP += 1
597
+ self.X = numpy.array(self.X)
598
+ self.Y = numpy.array(self.Y)
599
+ self.Z = numpy.array(self.Z)
600
+ # Define triangles for plotting
601
+ self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
602
+ iT = 0
603
+ for iTr in range(self.nf):
604
+ self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
605
+ self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
606
+ iT += 2
607
+
608
+ def translate(self, xT, yT, zT):
609
+ self.X += xT
610
+ self.Y += yT
611
+ self.Z += zT
612
+
613
+ def rotate(self, a1, a2, theta):
614
+ R = numpy.zeros([3, 3])
615
+ # Normal vector through origin
616
+ u = a2[0] - a1[0]
617
+ v = a2[1] - a1[1]
618
+ w = a2[2] - a1[2]
619
+ u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
620
+ v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
621
+ w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
622
+ # Translate mesh so that rotation axis starts from the origin
623
+ self.X -= a1[0]
624
+ self.Y -= a1[1]
625
+ self.Z -= a1[2]
626
+
627
+ # Rotation matrix
628
+ R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
629
+ R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
630
+ R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
631
+ R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
632
+ R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
633
+ R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
634
+ R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
635
+ R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
636
+ R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
637
+
638
+ for iP in range(self.np):
639
+ p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
640
+ p2 = numpy.dot(R, p1)
641
+ self.X[iP] = p2[0]
642
+ self.Y[iP] = p2[1]
643
+ self.Z[iP] = p2[2]
644
+
645
+ # Translate back to original position
646
+
647
+ self.X += a1[0]
648
+ self.Y += a1[1]
649
+ self.Z += a1[2]
650
+
651
+ def makeCoin(self):
652
+ coin = numpy.zeros((3, 4, self.nf))
653
+ for iF in range(self.nf):
654
+ for iC in range(4):
655
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
656
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
657
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
658
+ return coin
659
+
660
+
661
+
662
+
663
+
664
+ class hemisphere:
665
+ def __init__(self, diameter, cCor):
666
+ self.diameter = diameter
667
+ self.xC = cCor[0]
668
+ self.yC = cCor[1]
669
+ self.zC = cCor[2]
670
+ self.name = 'hemisphere'
671
+ self.panelize()
672
+ self.translate(self.xC, self.yC, self.zC)
673
+
674
+ def panelize(self):
675
+ Ntheta = 18
676
+ theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
677
+ phi = [xx * numpy.pi / 2.0 / (Ntheta / 2 - 1) for xx in range(Ntheta / 2)]
678
+ self.nf = 0
679
+ self.np = 0
680
+ r = self.diameter / 2.0
681
+ self.X = []
682
+ self.Y = []
683
+ self.Z = []
684
+ self.P = numpy.zeros([(Ntheta - 1) * (Ntheta / 2 - 1), 4], dtype=int)
685
+
686
+ for iT in range(Ntheta / 2):
687
+ for iTT in range(Ntheta):
688
+ self.X.append(r * numpy.cos(theta[iTT]) * numpy.sin(phi[iT]))
689
+ self.Y.append(r * numpy.sin(theta[iTT]) * numpy.sin(phi[iT]))
690
+ self.Z.append(-r * numpy.cos(phi[iT]))
691
+ self.np += 1
692
+
693
+ iP = 0
694
+ for iN in range(1, Ntheta):
695
+ for iT in range(1, Ntheta / 2):
696
+ self.P[iP, 0] = iN + Ntheta * (iT - 1)
697
+ self.P[iP, 1] = iN + 1 + Ntheta * (iT - 1)
698
+ self.P[iP, 2] = iN + 1 + Ntheta * iT
699
+ self.P[iP, 3] = iN + Ntheta * iT
700
+ self.nf += 1
701
+ iP += 1
702
+
703
+ self.X = numpy.array(self.X)
704
+ self.Y = numpy.array(self.Y)
705
+ self.Z = numpy.array(self.Z)
706
+ # Define triangles for plotting
707
+ self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
708
+ iT = 0
709
+ for iTr in range(self.nf):
710
+ self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
711
+ self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
712
+ iT += 2
713
+
714
+ def translate(self, xT, yT, zT):
715
+ self.X += xT
716
+ self.Y += yT
717
+ self.Z += zT
718
+
719
+ def rotate(self, a1, a2, theta):
720
+ R = numpy.zeros([3, 3])
721
+ # Normal vector through origin
722
+ u = a2[0] - a1[0]
723
+ v = a2[1] - a1[1]
724
+ w = a2[2] - a1[2]
725
+ u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
726
+ v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
727
+ w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
728
+ # Translate mesh so that rotation axis starts from the origin
729
+ self.X -= a1[0]
730
+ self.Y -= a1[1]
731
+ self.Z -= a1[2]
732
+
733
+ # Rotation matrix
734
+ R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
735
+ R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
736
+ R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
737
+ R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
738
+ R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
739
+ R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
740
+ R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
741
+ R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
742
+ R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
743
+
744
+ for iP in range(self.np):
745
+ p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
746
+ p2 = numpy.dot(R, p1)
747
+ self.X[iP] = p2[0]
748
+ self.Y[iP] = p2[1]
749
+ self.Z[iP] = p2[2]
750
+
751
+ # Translate back to original position
752
+
753
+ self.X += a1[0]
754
+ self.Y += a1[1]
755
+ self.Z += a1[2]
756
+
757
+ def makeCoin(self):
758
+ coin = numpy.zeros((3, 4, self.nf))
759
+ for iF in range(self.nf):
760
+ for iC in range(4):
761
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
762
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
763
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
764
+ return coin
765
+
766
+
767
+
768
+
769
+ class pyramid:
770
+ def __init__(self, length, width, height, cCor):
771
+ self.length = length
772
+ self.width = width
773
+ self.height = height
774
+ self.xC = cCor[0]
775
+ self.yC = cCor[1]
776
+ self.zC = cCor[2]
777
+ self.name = 'pyramid'
778
+ self.panelize()
779
+ self.translate(self.xC, self.yC, self.zC)
780
+
781
+ def panelize(self):
782
+ self.nf = 6
783
+ self.np = 8
784
+ self.X = numpy.array(
785
+ [0.0, 0.0, -self.length / 2.0, self.length / 2.0, 0.0, 0.0, -self.length / 2.0, self.length / 2.0])
786
+ self.Y = numpy.array(
787
+ [0.0, 0.0, self.width / 2.0, self.width / 2.0, 0.0, 0.0, -self.width / 2.0, -self.width / 2.0])
788
+ self.Z = numpy.array([-self.height, -self.height, 0.0, 0.0, -self.height, -self.height, 0.0, 0.0])
789
+ self.P = numpy.zeros([6, 4], dtype=int)
790
+ self.P[0, :] = numpy.array([3, 4, 2, 1])
791
+ self.P[1, :] = numpy.array([4, 8, 6, 2])
792
+ self.P[2, :] = numpy.array([8, 7, 5, 6])
793
+ self.P[3, :] = numpy.array([7, 3, 1, 5])
794
+ self.P[4, :] = numpy.array([5, 6, 5, 1])
795
+ self.P[5, :] = numpy.array([8, 4, 3, 7])
796
+ # Define triangles for plotting
797
+ self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
798
+ iT = 0
799
+ for iTr in range(self.nf):
800
+ self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
801
+ self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
802
+ iT += 2
803
+
804
+ def translate(self, xT, yT, zT):
805
+ self.X += xT
806
+ self.Y += yT
807
+ self.Z += zT
808
+
809
+ def rotate(self, a1, a2, theta):
810
+ R = numpy.zeros([3, 3])
811
+ # Normal vector through origin
812
+ u = a2[0] - a1[0]
813
+ v = a2[1] - a1[1]
814
+ w = a2[2] - a1[2]
815
+ u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
816
+ v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
817
+ w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
818
+ # Translate mesh so that rotation axis starts from the origin
819
+ self.X -= a1[0]
820
+ self.Y -= a1[1]
821
+ self.Z -= a1[2]
822
+
823
+ # Rotation matrix
824
+ R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
825
+ R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
826
+ R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
827
+ R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
828
+ R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
829
+ R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
830
+ R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
831
+ R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
832
+ R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
833
+
834
+ for iP in range(self.np):
835
+ p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
836
+ p2 = numpy.dot(R, p1)
837
+ self.X[iP] = p2[0]
838
+ self.Y[iP] = p2[1]
839
+ self.Z[iP] = p2[2]
840
+
841
+ # Translate back to original position
842
+
843
+ self.X += a1[0]
844
+ self.Y += a1[1]
845
+ self.Z += a1[2]
846
+
847
+ def makeCoin(self):
848
+ coin = numpy.zeros((3, 4, self.nf))
849
+ for iF in range(self.nf):
850
+ for iC in range(4):
851
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
852
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
853
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
854
+ return coin
855
+
856
+
857
+
858
+
859
+
860
+ class wedge:
861
+ def __init__(self, length, width, height, cCor):
862
+ self.length = length
863
+ self.width = width
864
+ self.height = height
865
+ self.xC = cCor[0]
866
+ self.yC = cCor[1]
867
+ self.zC = cCor[2]
868
+ self.name = 'wedge'
869
+ self.panelize()
870
+ self.translate(self.xC, self.yC, self.zC)
871
+
872
+ def panelize(self):
873
+ self.nf = 6
874
+ self.np = 8
875
+ self.X = numpy.array(
876
+ [0.0, 0.0, -self.length / 2.0, self.length / 2.0, 0.0, 0.0, -self.length / 2.0, self.length / 2.0])
877
+ self.Y = numpy.array([self.width / 2.0, self.width / 2.0, self.width / 2.0, self.width / 2.0, -self.width / 2.0,
878
+ -self.width / 2.0, -self.width / 2.0, -self.width / 2.0])
879
+ self.Z = numpy.array([-self.height, -self.height, 0.0, 0.0, -self.height, -self.height, 0.0, 0.0])
880
+ self.P = numpy.zeros([6, 4], dtype=int)
881
+ self.P[0, :] = numpy.array([3, 4, 2, 1])
882
+ self.P[1, :] = numpy.array([4, 8, 6, 2])
883
+ self.P[2, :] = numpy.array([8, 7, 5, 6])
884
+ self.P[3, :] = numpy.array([7, 3, 1, 5])
885
+ self.P[4, :] = numpy.array([2, 6, 5, 1])
886
+ self.P[5, :] = numpy.array([8, 4, 3, 7])
887
+ # Define triangles for plotting
888
+ self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
889
+ iT = 0
890
+ for iTr in range(self.nf):
891
+ self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
892
+ self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
893
+ iT += 2
894
+
895
+ def translate(self, xT, yT, zT):
896
+ self.X += xT
897
+ self.Y += yT
898
+ self.Z += zT
899
+
900
+ def rotate(self, a1, a2, theta):
901
+ R = numpy.zeros([3, 3])
902
+ # Normal vector through origin
903
+ u = a2[0] - a1[0]
904
+ v = a2[1] - a1[1]
905
+ w = a2[2] - a1[2]
906
+ u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
907
+ v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
908
+ w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
909
+ # Translate mesh so that rotation axis starts from the origin
910
+ self.X -= a1[0]
911
+ self.Y -= a1[1]
912
+ self.Z -= a1[2]
913
+
914
+ # Rotation matrix
915
+ R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
916
+ R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
917
+ R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
918
+ R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
919
+ R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
920
+ R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
921
+ R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
922
+ R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
923
+ R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
924
+
925
+ for iP in range(self.np):
926
+ p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
927
+ p2 = numpy.dot(R, p1)
928
+ self.X[iP] = p2[0]
929
+ self.Y[iP] = p2[1]
930
+ self.Z[iP] = p2[2]
931
+
932
+ # Translate back to original position
933
+
934
+ self.X += a1[0]
935
+ self.Y += a1[1]
936
+ self.Z += a1[2]
937
+
938
+ def makeCoin(self):
939
+ coin = numpy.zeros((3, 4, self.nf))
940
+ for iF in range(self.nf):
941
+ for iC in range(4):
942
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
943
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
944
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
945
+ return coin
946
+
947
+
948
+
949
+
950
+
951
+ class torus:
952
+ def __init__(self, diamOut, diamIn, cCor):
953
+ self.diamOut = diamOut
954
+ self.diamIn = diamIn
955
+ self.xC = cCor[0]
956
+ self.yC = cCor[1]
957
+ self.zC = cCor[2]
958
+ self.name = 'torus'
959
+ self.panelize()
960
+ self.translate(self.xC, self.yC, self.zC)
961
+
962
+ def panelize(self):
963
+ Ntheta = 18
964
+ Nphi = 18
965
+ theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
966
+ phi = [xx * 2 * numpy.pi / (Nphi - 1) for xx in range(Nphi)]
967
+ self.nf = 0
968
+ self.np = 0
969
+ self.X = []
970
+ self.Y = []
971
+ self.Z = []
972
+ R = self.diamOut / 2.0
973
+ r = self.diamIn / 2.0
974
+
975
+ for iT in range(Ntheta):
976
+ for iP in range(Nphi):
977
+ self.X.append((R + r * numpy.cos(theta[iT])) * numpy.cos(phi[iP]))
978
+ self.Y.append((R + r * numpy.cos(theta[iT])) * numpy.sin(phi[iP]))
979
+ self.Z.append(r * numpy.sin(theta[iT]))
980
+ self.np += 1
981
+
982
+ self.nf = (Ntheta - 1) * (Nphi - 1)
983
+ self.P = numpy.zeros([self.nf, 4], dtype=int)
984
+ iPan = 0
985
+ for iT in range(Ntheta - 1):
986
+ for iP in range(Nphi - 1):
987
+ self.P[iPan, 0] = iP + iT * Nphi + 1
988
+ self.P[iPan, 1] = iP + 1 + iT * Nphi + 1
989
+ self.P[iPan, 2] = iP + 1 + Ntheta + iT * Nphi + 1
990
+ self.P[iPan, 3] = iP + Ntheta + iT * Nphi + 1
991
+ iPan += 1
992
+
993
+ self.X = numpy.array(self.X)
994
+ self.Y = numpy.array(self.Y)
995
+ self.Z = numpy.array(self.Z)
996
+ # Define triangles for plotting
997
+ self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
998
+ iT = 0
999
+ for iTr in range(self.nf):
1000
+ self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
1001
+ self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
1002
+ iT += 2
1003
+
1004
+ def translate(self, xT, yT, zT):
1005
+ self.X += xT
1006
+ self.Y += yT
1007
+ self.Z += zT
1008
+
1009
+ def rotate(self, a1, a2, theta):
1010
+ R = numpy.zeros([3, 3])
1011
+ # Normal vector through origin
1012
+ u = a2[0] - a1[0]
1013
+ v = a2[1] - a1[1]
1014
+ w = a2[2] - a1[2]
1015
+ u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
1016
+ v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
1017
+ w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
1018
+ # Translate mesh so that rotation axis starts from the origin
1019
+ self.X -= a1[0]
1020
+ self.Y -= a1[1]
1021
+ self.Z -= a1[2]
1022
+
1023
+ # Rotation matrix
1024
+ R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
1025
+ R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
1026
+ R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
1027
+ R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
1028
+ R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
1029
+ R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
1030
+ R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
1031
+ R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
1032
+ R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
1033
+
1034
+ for iP in range(self.np):
1035
+ p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
1036
+ p2 = numpy.dot(R, p1)
1037
+ self.X[iP] = p2[0]
1038
+ self.Y[iP] = p2[1]
1039
+ self.Z[iP] = p2[2]
1040
+
1041
+ # Translate back to original position
1042
+
1043
+ self.X += a1[0]
1044
+ self.Y += a1[1]
1045
+ self.Z += a1[2]
1046
+
1047
+ def makeCoin(self):
1048
+ coin = numpy.zeros((3, 4, self.nf))
1049
+ for iF in range(self.nf):
1050
+ for iC in range(4):
1051
+ coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
1052
+ coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
1053
+ coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
1054
+ return coin
1055
+
1056
+
1057
+
1058
+ def make_voxels(shape, length, height, width, diameter):
1059
+ pos = [0, 0, 0]
1060
+ if shape == "box":
1061
+ mesh = box(length, width, height, pos)
1062
+ elif shape == "cone":
1063
+ mesh = cone(diameter, height, pos)
1064
+ elif shape == "cylinder":
1065
+ mesh = cylinder(diameter, height, pos)
1066
+ elif shape == "sphere":
1067
+ mesh = sphere(diameter, pos)
1068
+ elif shape == "wedge":
1069
+ mesh = wedge(length, width, height, pos)
1070
+
1071
+ hull_points = numpy.array([mesh.X.tolist(), mesh.Y.tolist(), mesh.Z.tolist()]).T
1072
+
1073
+ # Set up test points
1074
+ G = 32
1075
+ ex = 5 - 5 / G
1076
+ x, y, z = numpy.meshgrid(numpy.linspace(-ex, ex, G),
1077
+ numpy.linspace(-ex, ex, G),
1078
+ numpy.linspace(-(9.5 - 5 / G), 0.5 - 5 / G, G))
1079
+ test_points = numpy.vstack((x.ravel(), y.ravel(), z.ravel())).T
1080
+
1081
+ hull = scipy.spatial.Delaunay(hull_points)
1082
+ within = hull.find_simplex(test_points) >= 0
1083
+
1084
+ return plotly_fig(within*1.0)
1085
+
1086
  # This function loads a fuckton of data
1087
  def load_data():
1088
  # Open all the files we downloaded at the beginning and take out hte good bits
 
1106
 
1107
  # Return good bits to user
1108
  return curves, geometry, S, N, D, F, G, new_curves, new_geometry
 
 
 
1109
 
1110
  curves, geometry, S, N, D, F, G, new_curves, new_geometry = load_data()
1111