-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbahtinov.scad
264 lines (223 loc) · 8.14 KB
/
bahtinov.scad
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// ==========================================
// Bahtinov Mask Generator for OpenSCAD
// ==========================================
//
// Copyright (C) 2020 Jens Scheidtmann
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ==========================================
//////////////////////////////////////////////////////////////
//
// This project lives at:
// https://github.com/jscheidtmann/scad-bahtinov-mask
//
// Please see CONTRIBUTING.md, for how to contribute.
// CHANGELOG.md for a high level changelog and version
// information. The principle is explained and prior art is
// referenced in the README.md.
//
// Some example masks and a stable version of the generator
// can be downloaded from https://thingiverse.com/thingXXXXXXX
//
//////////////////////////////////////////////////////////////
//
// ************************************
// *** Some notes on implementation ***
// ************************************
//
// (0,0) is at the center of the mask.
//
// The "slits" and "bars" are created as repeats of cube elements.
// These are then translated, rotated and "cropped" to form the
// sectors of the mask.
//
// On top of that "support structure" is generated, in order to
// fuse the bars together and form a 2-manifold ("simple"),
// that can be exported as STL or DXF.
//
// "support structures" are
// - the ring around the mask,
// - the horizontal (hbar) and
// - vertical bars (vbar).
//
// On some elements the tolerance parameter is used to create
// slightly bigger elements, so that OpenSCAD is able to create
// the correct union of elements.
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
// Parameters used in configuration
//
// | |<- vbar
// _____ ____________________________
// _--- ---_ ________________ |
// -- \\ // -- | |
// / \\\\\ ///// \ | |
// / \\\\\\ ////// \ | dia_ext
// | \\\\\\\ /////// | | |
// | \\\\\\\ /////// | __ | |
// | | __ hbar | |
// | ||||||||||||||| | | |
// | ||||||||||||||| | dia_int |
// \ ||||||||||||| / | |
// \ ||||||||||| / | |
// --_ ||||| _-- ________________ |
// ---_____--- _________________________
//
//
///////////////////////////////////////////////////////////
//
// Dimensions of Mask
// (given in millimeter)
//
// exterior diameter, including the stabilizing ring
// AND holder structure (see below)
dia_ext = 60;
// interior diameter, this will be the area of the bars.
dia_int = 54;
// width of support structures
hbar = 3;
vbar = 3;
// thickness of mask
thickness = 1.5;
//
// Holder structure
//
// A cylinder of this height and wall thickness.
// Note that in order to be able to easily fit it over
// the telecopes aperture, the wall thickness is made
// thinner by a factor of 1/holder_thinning.
holder_height = 20;
holder_wall = 1.5;
holder_thinning = 3;
//
// Definition of bars, that make up the interference structure
//
// angle that the bars are tilted against each other in upper half.
angle = 15; // degrees
// define bar dimensions
focal_length = 200; // given in mm
// Factor to determine step size
bahtinov_const = 150; // [150-200]
bahtinov_factor = 1; // [1 or 3]
// step = bar + empty space
// if the step size becomes too small,
// increase the bahtinov_factor.
//
// rounded to next 1/10th of a mm
// WARNING: If this is extremly small, rendering time will be slow
step = round(10* focal_length / bahtinov_const * bahtinov_factor)/10;
echo("step = ", step);
// portion that will be bar (as part of "step")
portion = 1/2;
/////////////////////
// Implementation
/////////////////////
// Increase resolution of circles.
$fa = 1;
// ************************************************
// *** D O N O T C H A N G E ***
// *** B E L O W T H I S L I N E ! ! ! ***
// ************************************************
// (unless you know how, of course)
// tolerance to add for telling SCAD which things to merge
tolerance = 0.01;
// some derived things
radius = dia_int / 2;
radius_ext = dia_ext / 2;
no_bars = ceil(radius / step)+1;
// Note: half of them, due to radius
// Reapeat the bars.
// module bar_grid(no_bars, step, portion, length, thickness) {
// for (pos = [-no_bars*step : step : no_bars*step])
// translate([0,pos + step/4,0])
// cube([radius + tolerance,portion * step,thickness]);
// }
/// If you want to have a 2D file (SVG, DXF), e.g. for
/// lasercutting, other machining or print-out,
/// uncomment the following line:
// projection()
// Step -1)
// Create an explicit union, to allow for projection.
union() {
// Step 0)
// Make sure the bars are cut off in Step 4
difference(){
union() {
// Step 1)
// The bars (lower half)
for (pos = [-no_bars*step : step : no_bars*step])
translate([-radius-tolerance,pos + step/4,0])
cube([radius + tolerance,portion * step,thickness]);
// Step 2)
// The bars (tilted to right, top right)
difference() {
rotate([0,0,-angle/2])
for (pos = [-no_bars*step : step : no_bars*step])
translate([0,pos + step/4,0])
cube([radius + tolerance,portion * step,thickness]);
translate([0,0,-thickness/2])
cube([dia_int,dia_int,2*thickness]);
translate([-dia_int,-dia_int,-thickness/2])
cube([dia_int,2*dia_int,2*thickness]);
};
// Step 3)
// The bars (tilted to left, top left)
difference() {
rotate([0,0,angle/2])
for (pos = [-no_bars*step : step : no_bars*step])
translate([0,pos + step/4,0])
cube([radius + tolerance,portion * step,thickness]);
translate([0,-dia_int,-thickness/2])
cube([dia_int,dia_int,2*thickness]);
translate([-dia_int,-dia_int,-thickness/2])
cube([dia_int,2*dia_int,2*thickness]);
};
};
// Step 4)
// Chop off bars.
translate([0,0,-thickness])
difference() {
cylinder(r=radius_ext*2, h=thickness*2);
cylinder(r=radius_ext, h=thickness*2);
};
};
// Step 5)
// Support Structure: Ring
difference() {
cylinder(r=radius_ext,h=thickness);
cylinder(r=radius,h=thickness+tolerance);
};
// Step 6)
// Support Structure: Horizontal Bar
translate([-hbar/2,-radius-tolerance,0])
cube([hbar,dia_int+2*tolerance,thickness]);
// Step 7)
// Support Structure: Vertical Bar
translate([0,-hbar/2,0])
cube([radius+tolerance,hbar,thickness]);
// Holder Structure
//
translate([0,0,thickness-tolerance])
difference() {
cylinder(holder_height+tolerance, r=radius_ext);
cylinder(holder_height+tolerance,
radius_ext-holder_wall,
radius_ext-holder_wall/holder_thinning);
echo("Inner diameter = ", 2*(radius_ext-holder_wall));
echo("Inner diameter at mask = ", 2*(radius_ext-holder_wall/holder_thinning));
};
}; // union()