-
Notifications
You must be signed in to change notification settings - Fork 4
/
ToroidalChutePattern.py
75 lines (58 loc) · 2.18 KB
/
ToroidalChutePattern.py
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
import cairo
import math
import numpy as np
import scipy.integrate as integrate
from ChutePattern import ChutePattern
class ToroidalChutePattern(ChutePattern):
def __init__(self, diameter, num_panels, e, tangent_lines=True, line_length = None, spill_hole_diameter = 0, grid=True, seam_allowance=(10,10,10,10)):
self.line_length = line_length
self.r = diameter/4 * e
self.rt = diameter/2 - self.r
self.rs = spill_hole_diameter/2
self.num_panels = num_panels
self.tangent_lines = tangent_lines
super().__init__(grid, seam_allowance)
def _t(self, x):
return math.acos((x-self.rt)/self.r)
def _x(self, t):
return self.rt + math.cos(t) * self.r
def _y(self, t):
return self.rt + math.sin(t) * self.r
def _tangential_line_point(self):
l = self.line_length
r = self.r
rt = self.rt
x = l*(l*rt + r*math.sqrt(l**2 + r**2 - rt**2))/(l**2 + r**2)
return self._t(x)
def get_spill_diameter(self):
minx = self.rt - self.r
if (minx > self.rs):
rs = minx
print("WARNING: spill hole to small. Extend it to minimal possible size")
elif (self.rs >= self.rt):
print("WARNING: spill hole diameter to large. Scaling it down")
rs = self.rt
else:
rs = self.rs
return rs
def _get_pattern_path(self):
rs = self.get_spill_diameter()
tmin = -self._tangential_line_point()
tmax = self._t(rs)
n = 100
ts = np.linspace(tmin, tmax, n)
x = [self._x(t) for t in ts]
l = [(t-tmin) * self.r for t in ts]
u = np.array([math.pi*xe for xe in x]) / self.num_panels
right_x = u
right_y = l
left_x = [-e for e in u[::-1]]
left_y = [e for e in l[::-1]]
top_x = [right_x[-1], left_x[0]]
top_y = [right_y[-1], left_y[0]]
bottom_x = [left_x[-1], right_x[0]]
bottom_y = [left_y[-1], right_y[0]]
return {"right": zip(right_x, right_y),
"top": zip(top_x, top_y),
"left" : zip(left_x, left_y),
"bottom": zip(bottom_x, bottom_y)}