-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathneil_pollock_foil.py
More file actions
181 lines (140 loc) · 8.08 KB
/
Copy pathneil_pollock_foil.py
File metadata and controls
181 lines (140 loc) · 8.08 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
from math import sqrt
import matplotlib.pyplot as plt
import pymupdf # or import fitz
# See: http://www.boat-links.com/foils.html
# x is the position along the chord from 0 to 1
# y is the thickness at a given value of x
# t is the maximum thickness as a fraction of the chord
leading = 40
trailing = 40
trailing_cut_mm = 3
length_mm = 266
thickness_mm = 18.4
print_line_width_mm = 0.2
print_offset = 90
def genLeading(xle, x, t):
y = (t / 2) * ((8 * sqrt(x) / (3 * sqrt(xle))) - (2 * x / xle) + (pow(x,2) / (3*pow(xle,2))))
return y
def genTrailing(xte, x1, t):
y = (t / 2) * (1 - 3 * pow(x1,2) / (2 * pow(xte,2)) + pow(x1,3) / (2 * pow(xte,3)))
#y = (t / 2) * ((1 - 3 * pow(x,2)) / (2 * pow(xte,2)))
#y = (t / 2) * (pow(x,3) / (2 * pow(xte,3)))
return y
def genPollock(l, t, xle, xte):
data = []
for i in range(1001):
x = i / 1000.0
if x > 1:
break
if x <= xle:
data.append((x*l, genLeading(xle,x,t)))
elif x + xte >= 1:
x1 = x - (1 - xte)
data.append((x*l, genTrailing(xte,x1,t)))
else:
data.append((x*l, t/2))
return data
def mm_to_pts(x):
return x * 72 / 25.4
def relLine(page, xy, offset):
(x, y) = xy
(ox, oy) = offset
page.draw_line(xy, (x + ox, y + oy), color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
def text(page, coord, text, rotate=0):
page.insert_text(coord, text=text, fontname="helv", fontsize=6, color=(0, 0, 0), rotate=rotate, render_mode=0)
################################################################################
## leading-flat-trailing
foil_x = print_offset + mm_to_pts(20)
foil_y = print_offset + mm_to_pts(3)
doc = pymupdf.open()
page = doc.new_page()
prev = None
for xy in genPollock(length_mm, thickness_mm, leading/100, trailing/100):
# swap x/y to get more page space vertically
y = foil_y + mm_to_pts(xy[0])
x = foil_x - mm_to_pts(xy[1])
if prev is not None:
page.draw_line(prev, (x,y), color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
prev = (x,y)
# Leading edge
relLine(page, (foil_x, foil_y), (mm_to_pts(thickness_mm/2), 0)) # flat
relLine(page, (foil_x, foil_y), (0, -3)) # flat start tick
relLine(page, (foil_x + mm_to_pts(thickness_mm/2), foil_y), (0, -50)) # flat end tick
# trailing edge
relLine(page, (foil_x, foil_y + mm_to_pts(length_mm)), (mm_to_pts(thickness_mm/2), 0)) # flat
relLine(page, (foil_x, foil_y + mm_to_pts(length_mm)), (0, 3)) # flat start tick
relLine(page, (foil_x + mm_to_pts(thickness_mm/2), foil_y + mm_to_pts(length_mm)), (0, 50)) # flat end tick
if trailing_cut_mm is not None:
relLine(page, (foil_x, foil_y + mm_to_pts(length_mm - trailing_cut_mm)), (mm_to_pts(thickness_mm/2), 0))
relLine(page, (foil_x + mm_to_pts(thickness_mm/2), foil_y + mm_to_pts(length_mm - trailing_cut_mm)), (0, mm_to_pts(trailing_cut_mm - 0.5)))
text(page, (foil_x - mm_to_pts(thickness_mm/2), foil_y + mm_to_pts(length_mm)), text='cut', rotate=90)
# leading edge / trailing edge ticks
text(page, (foil_x - mm_to_pts(thickness_mm/2) - 3, foil_y + mm_to_pts(length_mm * 0.5 * (leading/100))), text="leading", rotate=90)
relLine(page, (foil_x - mm_to_pts(thickness_mm/2), foil_y + mm_to_pts(length_mm * (leading/100))), (-3, 0))
text(page, (foil_x - mm_to_pts(thickness_mm/2) - 3, foil_y + 0.5*mm_to_pts(length_mm * (leading/100)) + 0.5 * mm_to_pts(length_mm - length_mm * (trailing/100))), text="flat", rotate=90)
relLine(page, (foil_x - mm_to_pts(thickness_mm/2), foil_y + mm_to_pts(length_mm - length_mm * (trailing/100))), (-3, 0))
text(page, (foil_x - mm_to_pts(thickness_mm/2) - 3, foil_y + mm_to_pts(length_mm - length_mm * 0.5 * (trailing/100))), text="trailing", rotate=90)
# Horizontal scale
page.draw_line((print_offset/2, print_offset/2), (print_offset/2 + mm_to_pts(100), print_offset/2), color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
page.draw_line(
(print_offset/2 + mm_to_pts(100), print_offset/2 + 3),
(print_offset/2 + mm_to_pts(100), print_offset/2 - 3),
color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
text(page, (print_offset/2 + mm_to_pts(50), print_offset/2 - 3), text="100mm", rotate=0)
# Vertical scale
page.draw_line((print_offset/2, print_offset/2), (print_offset/2, mm_to_pts(100) + print_offset/2), color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
page.draw_line(
(print_offset/2 - 3, mm_to_pts(100) + print_offset/2),
(print_offset/2 + 3, mm_to_pts(100) + print_offset/2),
color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
text(page, (print_offset/2 - 3, print_offset/2 + mm_to_pts(50)), text="100mm", rotate=90)
################################################################################
## trailing-flat-leading
foil_x = print_offset + mm_to_pts(70)
foil_y = print_offset + mm_to_pts(3)
prev = None
for xy in genPollock(length_mm, thickness_mm, leading/100, trailing/100):
# swap x/y to get more page space vertically
y = foil_y + mm_to_pts(length_mm - xy[0])
x = foil_x - mm_to_pts(xy[1])
if prev is not None:
page.draw_line(prev, (x,y), color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
prev = (x,y)
# Leading edge
relLine(page, (foil_x, foil_y), (mm_to_pts(thickness_mm/2), 0)) # flat
relLine(page, (foil_x, foil_y), (0, -3)) # flat start tick
relLine(page, (foil_x + mm_to_pts(thickness_mm/2), foil_y), (0, -50)) # flat end tick
# trailing edge
relLine(page, (foil_x, foil_y + mm_to_pts(length_mm)), (mm_to_pts(thickness_mm/2), 0)) # flat
relLine(page, (foil_x, foil_y + mm_to_pts(length_mm)), (0, 3)) # flat start tick
relLine(page, (foil_x + mm_to_pts(thickness_mm/2), foil_y + mm_to_pts(length_mm)), (0, 50)) # flat end tick
if trailing_cut_mm is not None:
relLine(page, (foil_x, foil_y + mm_to_pts(trailing_cut_mm)), (mm_to_pts(thickness_mm/2), 0))
relLine(page, (foil_x + mm_to_pts(thickness_mm/2), foil_y + mm_to_pts(trailing_cut_mm)), (0, mm_to_pts(0.5 - trailing_cut_mm)))
text(page, (foil_x - mm_to_pts(thickness_mm/2), foil_y + 8), text='cut', rotate=90)
# leading edge / trailing edge ticks
relLine(page, (foil_x - mm_to_pts(thickness_mm/2), foil_y + mm_to_pts(length_mm * (trailing/100))), (-3, 0))
text(page, (foil_x - mm_to_pts(thickness_mm/2) - 3, foil_y + mm_to_pts(length_mm * 0.5 * (trailing/100))), text="trailing", rotate=90)
text(page, (foil_x - mm_to_pts(thickness_mm/2) - 3, foil_y + 0.5*mm_to_pts(length_mm - length_mm * (leading/100)) + 0.5 * mm_to_pts(length_mm * (trailing/100))), text="flat", rotate=90)
text(page, (foil_x - mm_to_pts(thickness_mm/2) - 3, foil_y + mm_to_pts(length_mm - length_mm * 0.5 * (leading/100))), text="leading", rotate=90)
relLine(page, (foil_x - mm_to_pts(thickness_mm/2), foil_y + mm_to_pts(length_mm - length_mm * (leading/100))), (-3, 0))
################################################################################
## legend & scales
# Legend
page.insert_text((mm_to_pts(130), print_offset/2 + mm_to_pts(1)), text=f"Neil Pollock Flat\nLength: {length_mm}mm\nThickness: {thickness_mm}mm / {length_mm/thickness_mm:.1f}%\nLeading Edge: {leading}%\nTrailing Edge: {trailing}%\nTrailing Cut: {trailing_cut_mm}mm", fontname="helv", fontsize=12, color=(0, 0, 0), rotate=0, render_mode=0)
# Horizontal scale
page.draw_line((print_offset/2, print_offset/2), (print_offset/2 + mm_to_pts(100), print_offset/2), color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
page.draw_line(
(print_offset/2 + mm_to_pts(100), print_offset/2 + 3),
(print_offset/2 + mm_to_pts(100), print_offset/2 - 3),
color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
text(page, (print_offset/2 + mm_to_pts(50), print_offset/2 - 3), text="100mm", rotate=0)
# Vertical scale
page.draw_line((print_offset/2, print_offset/2), (print_offset/2, mm_to_pts(100) + print_offset/2), color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
page.draw_line(
(print_offset/2 - 3, mm_to_pts(100) + print_offset/2),
(print_offset/2 + 3, mm_to_pts(100) + print_offset/2),
color=(0, 0, 0), width=mm_to_pts(print_line_width_mm))
text(page, (print_offset/2 - 3, print_offset/2 + mm_to_pts(50)), text="100mm", rotate=90)
doc.save(f"neil_polock_{length_mm}x{thickness_mm}_L{leading}_T{trailing}.pdf")
doc.close()