@rulecad/shapes 0.4.8 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/enclosure.mjs +69 -17
- package/features.mjs +73 -22
- package/ops.mjs +77 -17
- package/optimised.d.mts +5 -3
- package/optimised.mjs +32 -12
- package/package.json +6 -15
- package/seats.d.mts +1 -1
- package/seats.mjs +313 -63
- package/shapes.mjs +91 -31
package/seats.mjs
CHANGED
|
@@ -10,34 +10,70 @@
|
|
|
10
10
|
// clipGroove(shaft, { width, depth, at }) a ring to subtract from a printed shaft, stood up: flat below, sloped above
|
|
11
11
|
import jscad from '@jscad/modeling';
|
|
12
12
|
|
|
13
|
-
const { cylinder, cylinderElliptic, cuboid, polygon } = jscad.primitives,
|
|
14
|
-
|
|
15
|
-
const
|
|
13
|
+
const { cylinder, cylinderElliptic, cuboid, polygon } = jscad.primitives,
|
|
14
|
+
{ translate, rotateX, rotateY, rotateZ } = jscad.transforms;
|
|
15
|
+
const { hull } = jscad.hulls,
|
|
16
|
+
{ union } = jscad.booleans,
|
|
17
|
+
{ extrudeRotate } = jscad.extrusions;
|
|
18
|
+
const OUT = 0.1,
|
|
19
|
+
TINY = 1e-3,
|
|
20
|
+
EDGE = 0.05,
|
|
21
|
+
SEGMENTS = 64;
|
|
16
22
|
const UP = { '+x': [1, 0], '-x': [-1, 0], '+y': [0, 1], '-y': [0, -1] };
|
|
17
23
|
|
|
18
24
|
function along(g, into, at = [0, 0, 0]) {
|
|
19
|
-
const turn = {
|
|
20
|
-
'
|
|
25
|
+
const turn = {
|
|
26
|
+
'-z': (x) => x,
|
|
27
|
+
'+z': (x) => rotateX(Math.PI, x),
|
|
28
|
+
'+x': (x) => rotateY(-Math.PI / 2, x),
|
|
29
|
+
'-x': (x) => rotateY(Math.PI / 2, x),
|
|
30
|
+
'+y': (x) => rotateX(Math.PI / 2, x),
|
|
31
|
+
'-y': (x) => rotateX(-Math.PI / 2, x),
|
|
32
|
+
}[into];
|
|
21
33
|
if (!turn) throw new Error(`into must be +x, -x, +y, -y, +z or -z (got ${into})`);
|
|
22
34
|
return translate(at, turn(g));
|
|
23
35
|
}
|
|
24
|
-
function size(what, name, v, { zero = false } = {}) {
|
|
36
|
+
function size(what, name, v, { zero = false } = {}) {
|
|
37
|
+
if (!(typeof v === 'number' && Number.isFinite(v) && (zero ? v >= 0 : v > 0)))
|
|
38
|
+
throw new Error(`${what}: ${name} is a size ${zero ? 'of 0 mm or more' : 'above 0 mm'} (got ${v})`);
|
|
39
|
+
return v;
|
|
40
|
+
}
|
|
25
41
|
// A round cutter from z0 down to z1 (radius r0 to r1), with a 45° ridge on the up side when it goes across a part
|
|
26
42
|
function tear(r0, r1, z0, z1, up) {
|
|
27
|
-
const ridge = (r, z) =>
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
const ridge = (r, z) =>
|
|
44
|
+
translate(
|
|
45
|
+
[up[0] * (r * Math.SQRT2 - EDGE / Math.SQRT2), up[1] * (r * Math.SQRT2 - EDGE / Math.SQRT2), z],
|
|
46
|
+
rotateZ(Math.PI / 4, cuboid({ size: [EDGE, EDGE, TINY] })),
|
|
47
|
+
);
|
|
48
|
+
const round =
|
|
49
|
+
r0 === r1
|
|
50
|
+
? translate([0, 0, (z0 + z1) / 2], cylinder({ radius: r0, height: Math.abs(z0 - z1), segments: SEGMENTS }))
|
|
51
|
+
: translate(
|
|
52
|
+
[0, 0, (z0 + z1) / 2],
|
|
53
|
+
cylinderElliptic({
|
|
54
|
+
height: Math.abs(z0 - z1),
|
|
55
|
+
startRadius: [r1, r1],
|
|
56
|
+
endRadius: [r0, r0],
|
|
57
|
+
segments: SEGMENTS,
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
30
60
|
return up ? hull(round, ridge(r0, z0), ridge(r1, z1)) : round;
|
|
31
61
|
}
|
|
32
62
|
function printerOf(what, p) {
|
|
33
|
-
if (!p || typeof p !== 'object')
|
|
63
|
+
if (!p || typeof p !== 'object')
|
|
64
|
+
throw new Error(
|
|
65
|
+
`${what}: give the printer's rules ({ printer: v.x1c }): the fit is theirs, so there are no numbers here`,
|
|
66
|
+
);
|
|
34
67
|
return p;
|
|
35
68
|
}
|
|
36
69
|
const FITS = ['press', 'slip'];
|
|
37
70
|
function bearingOf(what, b) {
|
|
38
|
-
if (!b || typeof b !== 'object')
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
if (!b || typeof b !== 'object')
|
|
72
|
+
throw new Error(`${what}: give the bearing's rules ({ bore, outer_diameter, width }), not ${b}`);
|
|
73
|
+
const outer = b.outer_diameter ?? b.outer,
|
|
74
|
+
bore = size(what, 'bore', b.bore);
|
|
75
|
+
if (!(size(what, 'outer_diameter', outer) > bore))
|
|
76
|
+
throw new Error(`${what}: the outer diameter (${outer}) is above the bore (${bore})`);
|
|
41
77
|
return { bore, outer, width: size(what, 'width', b.width) };
|
|
42
78
|
}
|
|
43
79
|
|
|
@@ -52,17 +88,32 @@ function bearingOf(what, b) {
|
|
|
52
88
|
* pocket: the diameter as drawn; relief: the diameter past the ledge; clearance: what's left across it once printed (below 0, a press)
|
|
53
89
|
*/
|
|
54
90
|
export function seatSize(bearing, { fit = 'press', lip, printer } = {}) {
|
|
55
|
-
const what = 'bearingSeat',
|
|
91
|
+
const what = 'bearingSeat',
|
|
92
|
+
b = bearingOf(what, bearing),
|
|
93
|
+
p = printerOf(what, printer),
|
|
94
|
+
comp = size(what, 'printer.hole_comp', p.hole_comp, { zero: true });
|
|
56
95
|
let clearance;
|
|
57
96
|
if (typeof fit === 'number') clearance = fit;
|
|
58
97
|
else if (fit === 'press') clearance = -size(what, 'printer.press', p.press, { zero: true });
|
|
59
98
|
else if (fit === 'slip') clearance = size(what, 'printer.slip', p.slip, { zero: true });
|
|
60
99
|
else throw new Error(`${what}: fit is ${FITS.join(' or ')}, or a clearance in mm (got ${fit})`);
|
|
61
|
-
const radial = (b.outer - b.bore) / 2,
|
|
100
|
+
const radial = (b.outer - b.bore) / 2,
|
|
101
|
+
ledge = lip ?? radial / 4;
|
|
62
102
|
size(what, 'lip', ledge);
|
|
63
|
-
if (ledge > radial / 2)
|
|
103
|
+
if (ledge > radial / 2)
|
|
104
|
+
throw new Error(
|
|
105
|
+
`${what}: a lip of ${ledge} mm reaches the inner race (the races are ${radial} mm deep together: ${radial / 2} mm at most)`,
|
|
106
|
+
);
|
|
64
107
|
const pocket = b.outer + comp + clearance;
|
|
65
|
-
return {
|
|
108
|
+
return {
|
|
109
|
+
pocket: +pocket.toFixed(4),
|
|
110
|
+
depth: b.width,
|
|
111
|
+
relief: +(pocket - 2 * ledge).toFixed(4),
|
|
112
|
+
lip: ledge,
|
|
113
|
+
fit,
|
|
114
|
+
clearance,
|
|
115
|
+
comp,
|
|
116
|
+
};
|
|
66
117
|
}
|
|
67
118
|
|
|
68
119
|
/**
|
|
@@ -74,18 +125,61 @@ export function seatSize(bearing, { fit = 'press', lip, printer } = {}) {
|
|
|
74
125
|
* relief: how far past the ledge (mm); through: run the relief out of the far face; lead: the lead-in chamfer at the mouth (none across a part, where its top half would overhang)
|
|
75
126
|
* @returns {object} a JSCAD geom3 to subtract, with .seat holding seatSize's numbers
|
|
76
127
|
*/
|
|
77
|
-
export function bearingSeat(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
128
|
+
export function bearingSeat(
|
|
129
|
+
bearing,
|
|
130
|
+
{
|
|
131
|
+
fit = 'press',
|
|
132
|
+
lip,
|
|
133
|
+
relief = 1,
|
|
134
|
+
through = false,
|
|
135
|
+
into = '-z',
|
|
136
|
+
lead = UP[into] ? 0 : 0.4,
|
|
137
|
+
printer,
|
|
138
|
+
at = [0, 0, 0],
|
|
139
|
+
} = {},
|
|
140
|
+
) {
|
|
141
|
+
const what = 'bearingSeat',
|
|
142
|
+
s = seatSize(bearing, { fit, lip, printer });
|
|
143
|
+
size(what, 'relief', relief);
|
|
144
|
+
size(what, 'lead', lead, { zero: true });
|
|
145
|
+
const R = s.pocket / 2,
|
|
146
|
+
r = s.relief / 2,
|
|
147
|
+
up = UP[into] ?? null,
|
|
148
|
+
D = s.depth,
|
|
149
|
+
past = D + relief + (through ? OUT : 0);
|
|
150
|
+
if (up) {
|
|
151
|
+
// across a part, a teardrop's roof on each step
|
|
82
152
|
const cuts = [tear(R, R, lead ? 0 : OUT, -D, up), tear(r, r, -D + EDGE, -past, up)];
|
|
83
153
|
if (lead) cuts.push(tear(R + lead, R, 0, -lead, up), tear(R + lead, R + lead, OUT, 0, up));
|
|
84
154
|
return Object.assign(along(union(cuts), into, at), { seat: s });
|
|
85
155
|
}
|
|
86
156
|
// Going up or down, one profile turned about the axis: no seams between the steps for a boolean to leak at
|
|
87
|
-
const mouth = lead
|
|
88
|
-
|
|
157
|
+
const mouth = lead
|
|
158
|
+
? [
|
|
159
|
+
[R + lead, OUT],
|
|
160
|
+
[R + lead, 0],
|
|
161
|
+
[R, -lead],
|
|
162
|
+
]
|
|
163
|
+
: [[R, OUT]],
|
|
164
|
+
z0 = -D,
|
|
165
|
+
floor = through ? Math.min(-past, -D - R) - OUT : -past;
|
|
166
|
+
const inner =
|
|
167
|
+
into === '+z'
|
|
168
|
+
? through
|
|
169
|
+
? [
|
|
170
|
+
[R, z0],
|
|
171
|
+
[r, z0 - (R - r)],
|
|
172
|
+
[r, floor],
|
|
173
|
+
]
|
|
174
|
+
: [
|
|
175
|
+
[R, z0],
|
|
176
|
+
[TINY, z0 - (R - TINY)],
|
|
177
|
+
]
|
|
178
|
+
: [
|
|
179
|
+
[R, z0],
|
|
180
|
+
[r, z0],
|
|
181
|
+
[r, -past],
|
|
182
|
+
];
|
|
89
183
|
const pts = [[0, OUT], ...mouth, ...inner, [0, inner.at(-1)[1]]].reverse();
|
|
90
184
|
const turned = extrudeRotate({ segments: SEGMENTS }, polygon({ points: pts }));
|
|
91
185
|
const g = along(turned, into, at);
|
|
@@ -99,8 +193,23 @@ export function bearingSeat(bearing, { fit = 'press', lip, relief = 1, through =
|
|
|
99
193
|
* @type {Record<'slide' | 'press', { value: number, unit: string, rule: string, kind: string, source: string, checked: string }>}
|
|
100
194
|
*/
|
|
101
195
|
export const SHAFT_FITS = {
|
|
102
|
-
slide: {
|
|
103
|
-
|
|
196
|
+
slide: {
|
|
197
|
+
value: 0.05,
|
|
198
|
+
unit: 'mm',
|
|
199
|
+
rule: "Gap each side of a shaft in its bore, with the printed hole's shrinkage allowed for, so it slides on and no more: a 5 mm D-shaft slides comfortably in a bore drawn 5.2 mm (0.05 each side and hole_comp 0.1), is tight in 5.1 mm and will not go in 5.0 mm",
|
|
200
|
+
kind: 'measured',
|
|
201
|
+
source: 'fit bar row 2, examples/bench/projects/benchmarks/MEASURE.md row 3, PLA on the X1C',
|
|
202
|
+
checked: '2026-11-10',
|
|
203
|
+
},
|
|
204
|
+
press: {
|
|
205
|
+
value: -0.02,
|
|
206
|
+
unit: 'mm',
|
|
207
|
+
rule: "Each side of a shaft in a press-fit bore as printed: a hair tight, 0.8% strain on a 5 mm shaft, well inside what PLA stretches to before it cracks. A D flat does the driving. A bore drawn 5.06 mm for a 5 mm shaft falls between the fit bar's 5.1 mm (tight) and 5.0 mm (too tight)",
|
|
208
|
+
kind: 'estimate',
|
|
209
|
+
source:
|
|
210
|
+
"A reasoned guess, between the fit bar's tight and too tight bores (examples/bench/projects/benchmarks/MEASURE.md row 3); not yet pressed and turned under load",
|
|
211
|
+
checked: '2026-11-10',
|
|
212
|
+
},
|
|
104
213
|
};
|
|
105
214
|
const SHAFT_FIT_NAMES = ['slide', 'press', 'run'];
|
|
106
215
|
|
|
@@ -122,16 +231,31 @@ export function shaftBore(shaft, { fit = 'slide', across, printer, what = 'shaft
|
|
|
122
231
|
size(what, 'shaft', shaft);
|
|
123
232
|
// hole_comp may be below 0 here, for a printer whose holes come out large: motors' bore has always taken one
|
|
124
233
|
const comp = p.hole_comp;
|
|
125
|
-
if (!(typeof comp === 'number' && Number.isFinite(comp)))
|
|
234
|
+
if (!(typeof comp === 'number' && Number.isFinite(comp)))
|
|
235
|
+
throw new Error(
|
|
236
|
+
`${what}: printer.hole_comp is a number of mm, how much smaller across a printed hole comes out (got ${comp})`,
|
|
237
|
+
);
|
|
126
238
|
let each, kind;
|
|
127
|
-
if (typeof fit === 'number') {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
239
|
+
if (typeof fit === 'number') {
|
|
240
|
+
if (!Number.isFinite(fit) || 2 * fit + comp <= -shaft)
|
|
241
|
+
throw new Error(
|
|
242
|
+
`${what}: a fit of ${fit} mm each side${comp < 0 ? ` and hole_comp ${comp}` : ''} leaves no bore for a ${shaft} mm shaft`,
|
|
243
|
+
);
|
|
244
|
+
each = fit;
|
|
245
|
+
kind = 'given';
|
|
246
|
+
} else if (fit === 'run') {
|
|
247
|
+
each = size(what, 'printer.fit', p.fit);
|
|
248
|
+
kind = 'derived';
|
|
249
|
+
} else if (typeof fit === 'string' && Object.hasOwn(SHAFT_FITS, fit)) {
|
|
250
|
+
each = SHAFT_FITS[fit].value;
|
|
251
|
+
kind = SHAFT_FITS[fit].kind;
|
|
252
|
+
} else throw new Error(`${what}: fit is ${SHAFT_FIT_NAMES.join(', ')}, or a gap each side in mm (got ${fit})`);
|
|
131
253
|
const out = { diameter: +(shaft + 2 * each + comp).toFixed(4), each, comp, fit, kind };
|
|
132
|
-
if (!(out.diameter > 0))
|
|
254
|
+
if (!(out.diameter > 0))
|
|
255
|
+
throw new Error(`${what}: hole_comp ${comp} leaves no bore for a ${shaft} mm shaft at ${fit}`);
|
|
133
256
|
if (across != null) {
|
|
134
|
-
if (size(what, 'across', across) > shaft)
|
|
257
|
+
if (size(what, 'across', across) > shaft)
|
|
258
|
+
throw new Error(`${what}: across the flat (${across}) is at most the shaft's diameter, ${shaft} mm`);
|
|
135
259
|
out.across = +(across + 2 * each + comp).toFixed(4);
|
|
136
260
|
}
|
|
137
261
|
return out;
|
|
@@ -147,17 +271,45 @@ export function shaftBore(shaft, { fit = 'slide', across, printer, what = 'shaft
|
|
|
147
271
|
* side in mm, the same as a number for fit
|
|
148
272
|
* @returns {object} a JSCAD geom3, with .bore the diameter as drawn and .clearance each side
|
|
149
273
|
*/
|
|
150
|
-
export function plainBearing(
|
|
274
|
+
export function plainBearing(
|
|
275
|
+
shaft,
|
|
276
|
+
{ fit, clearance, length, wall, through = false, printer, at = [0, 0, 0], into = '-z', what = 'plainBearing' } = {},
|
|
277
|
+
) {
|
|
151
278
|
printerOf(what, printer);
|
|
152
|
-
size(what, 'shaft', shaft);
|
|
153
|
-
|
|
279
|
+
size(what, 'shaft', shaft);
|
|
280
|
+
size(what, 'length', length);
|
|
281
|
+
if (clearance != null && fit != null)
|
|
282
|
+
throw new Error(`${what}: give fit or clearance, not both: a clearance is a fit in mm each side`);
|
|
154
283
|
if (clearance != null) size(what, 'clearance', clearance);
|
|
155
|
-
const b = shaftBore(shaft, { fit: clearance ?? fit ?? 'run', printer, what }),
|
|
156
|
-
|
|
284
|
+
const b = shaftBore(shaft, { fit: clearance ?? fit ?? 'run', printer, what }),
|
|
285
|
+
bore = b.diameter,
|
|
286
|
+
gap = b.each;
|
|
287
|
+
if (wall == null)
|
|
288
|
+
return Object.assign(
|
|
289
|
+
along(tear(bore / 2, bore / 2, OUT, -length - (through ? OUT : 0), UP[into] ?? null), into, at),
|
|
290
|
+
{ bore, clearance: gap, fit: b.fit, kind: b.kind },
|
|
291
|
+
);
|
|
157
292
|
size(what, 'wall', wall);
|
|
158
|
-
if (UP[into])
|
|
159
|
-
|
|
160
|
-
|
|
293
|
+
if (UP[into])
|
|
294
|
+
throw new Error(
|
|
295
|
+
`${what}: a bush with a wall prints standing up (into +z or -z): a tube on its side wouldn't print round. Bore across a part with no wall instead`,
|
|
296
|
+
);
|
|
297
|
+
const outer = bore / 2 + wall,
|
|
298
|
+
inner = bore / 2,
|
|
299
|
+
chamfer = Math.min(0.4, wall / 2);
|
|
300
|
+
const g = extrudeRotate(
|
|
301
|
+
{ segments: SEGMENTS },
|
|
302
|
+
polygon({
|
|
303
|
+
points: [
|
|
304
|
+
[inner + chamfer, 0],
|
|
305
|
+
[outer - chamfer, 0],
|
|
306
|
+
[outer, chamfer],
|
|
307
|
+
[outer, length],
|
|
308
|
+
[inner, length],
|
|
309
|
+
[inner, chamfer],
|
|
310
|
+
],
|
|
311
|
+
}),
|
|
312
|
+
);
|
|
161
313
|
return Object.assign(translate(at, g), { bore, clearance: gap, fit: b.fit, kind: b.kind });
|
|
162
314
|
}
|
|
163
315
|
|
|
@@ -169,12 +321,31 @@ export function plainBearing(shaft, { fit, clearance, length, wall, through = fa
|
|
|
169
321
|
* @returns {object} a JSCAD geom3 to add
|
|
170
322
|
*/
|
|
171
323
|
export function shaftShoulder(shaft, { shoulder, height, at = [0, 0, 0] } = {}) {
|
|
172
|
-
const what = 'shaftShoulder',
|
|
324
|
+
const what = 'shaftShoulder',
|
|
325
|
+
a = size(what, 'shaft', shaft) / 2,
|
|
326
|
+
b = size(what, 'shoulder', shoulder) / 2;
|
|
173
327
|
size(what, 'height', height);
|
|
174
328
|
if (b <= a) throw new Error(`${what}: the shoulder (${shoulder}) stands proud of the shaft (${shaft})`);
|
|
175
|
-
if (height < b - a)
|
|
329
|
+
if (height < b - a)
|
|
330
|
+
throw new Error(
|
|
331
|
+
`${what}: a ${shoulder} mm collar on a ${shaft} mm shaft is ${b - a} mm of 45° underside, and ${height} mm isn't enough to draw it`,
|
|
332
|
+
);
|
|
176
333
|
// the solid runs in to the axis, so it joins the shaft whatever the shaft is drawn as
|
|
177
|
-
return translate(
|
|
334
|
+
return translate(
|
|
335
|
+
at,
|
|
336
|
+
extrudeRotate(
|
|
337
|
+
{ segments: SEGMENTS },
|
|
338
|
+
polygon({
|
|
339
|
+
points: [
|
|
340
|
+
[0, -height],
|
|
341
|
+
[a - TINY, -height],
|
|
342
|
+
[b, -height + (b - a) + TINY],
|
|
343
|
+
[b, 0],
|
|
344
|
+
[0, 0],
|
|
345
|
+
],
|
|
346
|
+
}),
|
|
347
|
+
),
|
|
348
|
+
);
|
|
178
349
|
}
|
|
179
350
|
|
|
180
351
|
/**
|
|
@@ -185,13 +356,28 @@ export function shaftShoulder(shaft, { shoulder, height, at = [0, 0, 0] } = {})
|
|
|
185
356
|
* @returns {object} a JSCAD geom3 to subtract, with .root the diameter at the groove's root
|
|
186
357
|
*/
|
|
187
358
|
export function clipGroove(shaft, { width, depth, at = [0, 0, 0] } = {}) {
|
|
188
|
-
const what = 'clipGroove',
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
359
|
+
const what = 'clipGroove',
|
|
360
|
+
R = size(what, 'shaft', shaft) / 2;
|
|
361
|
+
size(what, 'width', width);
|
|
362
|
+
size(what, 'depth', depth);
|
|
363
|
+
if (depth >= R / 2)
|
|
364
|
+
throw new Error(`${what}: a groove ${depth} mm deep leaves too little of a ${shaft} mm shaft (under ${R / 2} mm)`);
|
|
365
|
+
const r = R - depth,
|
|
366
|
+
over = R + 1,
|
|
367
|
+
rise = 1.2 * (over - r);
|
|
192
368
|
// The upper face is a little steeper than 45° (a slope of exactly the limit is an overhang by a hair, sliced). The
|
|
193
369
|
// cutter's outside runs 1 mm past the shaft, with its slope carried on so the face is one line
|
|
194
|
-
const g = extrudeRotate(
|
|
370
|
+
const g = extrudeRotate(
|
|
371
|
+
{ segments: SEGMENTS },
|
|
372
|
+
polygon({
|
|
373
|
+
points: [
|
|
374
|
+
[r, 0],
|
|
375
|
+
[over, 0],
|
|
376
|
+
[over, width + rise],
|
|
377
|
+
[r, width],
|
|
378
|
+
],
|
|
379
|
+
}),
|
|
380
|
+
);
|
|
195
381
|
return Object.assign(translate(at, g), { root: 2 * r });
|
|
196
382
|
}
|
|
197
383
|
|
|
@@ -202,10 +388,26 @@ export function clipGroove(shaft, { width, depth, at = [0, 0, 0] } = {}) {
|
|
|
202
388
|
* @param {{ fit?: 'press' | 'slip' | number, clearance?: number, through?: boolean, printer: object, at?: number[], into?: string }} o clearance: round the rod, each side
|
|
203
389
|
* @returns {object} a JSCAD geom3 to subtract, with .pocket the diameter as drawn
|
|
204
390
|
*/
|
|
205
|
-
export function lm8uuPocket(
|
|
206
|
-
|
|
391
|
+
export function lm8uuPocket(
|
|
392
|
+
bearing,
|
|
393
|
+
{ fit = 'press', clearance = 1, through = false, printer, at = [0, 0, 0], into = '-z' } = {},
|
|
394
|
+
) {
|
|
395
|
+
const what = 'lm8uuPocket',
|
|
396
|
+
p = printerOf(what, printer),
|
|
397
|
+
L = size(what, 'length', bearing?.length),
|
|
398
|
+
s = seatSize(
|
|
399
|
+
{ bore: bearing?.bore, outer_diameter: bearing?.outer_diameter, width: L },
|
|
400
|
+
{ fit, printer: p, lip: 0.01 },
|
|
401
|
+
),
|
|
402
|
+
up = UP[into] ?? null,
|
|
403
|
+
R = s.pocket / 2,
|
|
404
|
+
rod = bearing.bore / 2 + clearance;
|
|
207
405
|
const cuts = [tear(R, R, OUT, -L, up)];
|
|
208
|
-
if (into === '+z') {
|
|
406
|
+
if (into === '+z') {
|
|
407
|
+
const rise = R - rod;
|
|
408
|
+
cuts.push(tear(R, rod, -L, -L - rise));
|
|
409
|
+
cuts.push(tear(rod, rod, -L - rise / 2, -(L + rise + (through ? OUT : 2))));
|
|
410
|
+
} else cuts.push(tear(rod, rod, -L + EDGE, -(L + 2 + (through ? OUT : 0)), up));
|
|
209
411
|
return Object.assign(along(union(cuts), into, at), { pocket: s.pocket, clearance: s.clearance });
|
|
210
412
|
}
|
|
211
413
|
|
|
@@ -214,7 +416,10 @@ export function lm8uuPocket(bearing, { fit = 'press', clearance = 1, through = f
|
|
|
214
416
|
function screwHole(what, given, part, comp) {
|
|
215
417
|
if (given != null) return size(what, 'hole', given);
|
|
216
418
|
const own = part.hole_diameter ?? part.mount_hole_diameter;
|
|
217
|
-
if (own == null)
|
|
419
|
+
if (own == null)
|
|
420
|
+
throw new Error(
|
|
421
|
+
`${what}: give the screws' hole as drawn ({ hole: fixings.holeModel('M3', { printer }).diameter }), or the part's own hole_diameter: there is no screw size here`,
|
|
422
|
+
);
|
|
218
423
|
return size(what, 'hole_diameter', own) + comp;
|
|
219
424
|
}
|
|
220
425
|
|
|
@@ -232,11 +437,32 @@ function screwHole(what, given, part, comp) {
|
|
|
232
437
|
* @returns {object} a JSCAD geom3 to subtract, with .flange and .body the diameters as drawn, and .hole the screws' holes as drawn
|
|
233
438
|
*/
|
|
234
439
|
export function nutTrap(nut, { fit, hole: hole_, printer, at = [0, 0, 0], depth } = {}) {
|
|
235
|
-
const what = 'nutTrap',
|
|
440
|
+
const what = 'nutTrap',
|
|
441
|
+
p = printerOf(what, printer),
|
|
442
|
+
comp = size(what, 'printer.hole_comp', p.hole_comp, { zero: true }),
|
|
443
|
+
gap = fit ?? 2 * size(what, 'printer.fit', p.fit),
|
|
444
|
+
flange = size(what, 'flange_diameter', nut?.flange_diameter),
|
|
445
|
+
body = size(what, 'body_diameter', nut.body_diameter),
|
|
446
|
+
length = size(what, 'length', nut.length),
|
|
447
|
+
circle = size(what, 'hole_circle', nut.hole_circle),
|
|
448
|
+
n = size(what, 'hole_count', nut.hole_count);
|
|
236
449
|
const hole = screwHole(what, hole_, nut, comp);
|
|
237
|
-
const t = nut.flange_thickness ?? nut.flange_width ?? 3.5,
|
|
238
|
-
|
|
239
|
-
|
|
450
|
+
const t = nut.flange_thickness ?? nut.flange_width ?? 3.5,
|
|
451
|
+
D = depth ?? length,
|
|
452
|
+
r = (body + comp + gap) / 2,
|
|
453
|
+
R = (flange + comp + gap) / 2;
|
|
454
|
+
if (circle / 2 + (hole - comp) / 2 > R + 0.01 || circle / 2 - (hole - comp) / 2 < r)
|
|
455
|
+
throw new Error(
|
|
456
|
+
`nutTrap: holes on a ${circle} mm circle don't fall between the ${body} mm body and the ${flange} mm flange`,
|
|
457
|
+
);
|
|
458
|
+
const cuts = [tear(R, R, OUT, -t), tear(r, r, -t + EDGE, -D - OUT)],
|
|
459
|
+
holes = Array.from({ length: n }, (_, i) => {
|
|
460
|
+
const a = (i * 2 * Math.PI) / n;
|
|
461
|
+
return translate(
|
|
462
|
+
[(circle / 2) * Math.cos(a), (circle / 2) * Math.sin(a), 0],
|
|
463
|
+
tear(hole / 2, hole / 2, 0, -D - OUT),
|
|
464
|
+
);
|
|
465
|
+
});
|
|
240
466
|
return Object.assign(translate(at, union(...cuts, ...holes)), { flange: 2 * R, body: 2 * r, hole });
|
|
241
467
|
}
|
|
242
468
|
|
|
@@ -248,8 +474,19 @@ export function nutTrap(nut, { fit, hole: hole_, printer, at = [0, 0, 0], depth
|
|
|
248
474
|
* fit: as shaftBore (default slide); run, for an idler that turns on its axle
|
|
249
475
|
* @returns {object} a JSCAD geom3 to subtract, with .bore the diameter as drawn and .clearance each side
|
|
250
476
|
*/
|
|
251
|
-
export function pulleyBore(
|
|
252
|
-
|
|
477
|
+
export function pulleyBore(
|
|
478
|
+
pulley,
|
|
479
|
+
{ length, fit = 'slide', printer, at = [0, 0, 0], into = '-z', through = false } = {},
|
|
480
|
+
) {
|
|
481
|
+
return plainBearing(size('pulleyBore', 'bore', pulley?.bore), {
|
|
482
|
+
length,
|
|
483
|
+
fit,
|
|
484
|
+
printer,
|
|
485
|
+
at,
|
|
486
|
+
into,
|
|
487
|
+
through,
|
|
488
|
+
what: 'pulleyBore',
|
|
489
|
+
});
|
|
253
490
|
}
|
|
254
491
|
|
|
255
492
|
/**
|
|
@@ -259,9 +496,22 @@ export function pulleyBore(pulley, { length, fit = 'slide', printer, at = [0, 0,
|
|
|
259
496
|
* @returns {object} a JSCAD geom3 to add, x along the belt, z up
|
|
260
497
|
*/
|
|
261
498
|
export function beltClamp(belt, { length, height, wall, at = [0, 0, 0] } = {}) {
|
|
262
|
-
const what = 'beltClamp',
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
499
|
+
const what = 'beltClamp',
|
|
500
|
+
pitch = size(what, 'pitch', belt?.pitch),
|
|
501
|
+
width = size(what, 'width', belt.width);
|
|
502
|
+
size(what, 'length', length);
|
|
503
|
+
size(what, 'height', height);
|
|
504
|
+
size(what, 'wall', wall);
|
|
505
|
+
const count = Math.floor(length / pitch),
|
|
506
|
+
base = translate([0, 0, height / 2], cuboid({ size: [length, width + 2 * wall, height] })),
|
|
507
|
+
teeth = [],
|
|
508
|
+
tooth = pitch * 0.45;
|
|
509
|
+
for (let i = 0; i < count; i++)
|
|
510
|
+
teeth.push(
|
|
511
|
+
translate(
|
|
512
|
+
[-length / 2 + pitch * (i + 0.5), 0, height + 0.375],
|
|
513
|
+
cuboid({ size: [tooth, width + 2 * wall, 0.75] }),
|
|
514
|
+
),
|
|
515
|
+
);
|
|
266
516
|
return translate(at, union(base, ...teeth));
|
|
267
517
|
}
|