@rulecad/frames 0.0.1 → 0.1.8
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 +23 -0
- package/README.md +1182 -21
- package/beam.d.mts +145 -0
- package/beam.mjs +201 -0
- package/bought.d.mts +60 -0
- package/bought.mjs +195 -0
- package/catalogue.d.mts +20 -0
- package/catalogue.mjs +268 -0
- package/cutlist.d.mts +88 -0
- package/cutlist.mjs +199 -0
- package/cutsheet.d.mts +23 -0
- package/cutsheet.mjs +118 -0
- package/door.d.mts +127 -0
- package/door.mjs +254 -0
- package/ends.d.mts +130 -0
- package/ends.mjs +290 -0
- package/fitting.d.mts +262 -0
- package/fitting.mjs +535 -0
- package/frames.d.mts +18 -9
- package/frames.mjs +43 -10
- package/guide.d.mts +140 -0
- package/guide.mjs +269 -0
- package/jig.d.mts +146 -0
- package/jig.mjs +332 -0
- package/join.d.mts +244 -0
- package/join.mjs +257 -0
- package/ops.d.mts +44 -0
- package/ops.mjs +324 -0
- package/package.json +75 -8
- package/panel.d.mts +225 -0
- package/panel.mjs +374 -0
- package/profile.d.mts +268 -0
- package/profile.mjs +462 -0
- package/rods.d.mts +195 -0
- package/rods.mjs +475 -0
- package/section.d.mts +43 -0
- package/section.mjs +140 -0
- package/services.d.mts +335 -0
- package/services.mjs +486 -0
- package/slotnut.d.mts +210 -0
- package/slotnut.mjs +394 -0
- package/square.d.mts +23 -0
- package/square.mjs +42 -0
- package/wheels.d.mts +141 -0
- package/wheels.mjs +337 -0
package/panel.d.mts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/** @internal The common setup of a printed part: printer, plastic and their figures. @param {string} what @param {object} o @returns {any} */
|
|
2
|
+
export function partSetup(what: string, o: object): any;
|
|
3
|
+
/** @internal A sheet's thickness, refused by name. @param {string} what @param {any} t @returns {number} */
|
|
4
|
+
export function sheetThickness(what: string, t: any): number;
|
|
5
|
+
/** @internal A load in N, refused by name. @param {string} what @param {any} F @param {string} said @returns {void} */
|
|
6
|
+
export function loadOk(what: string, F: any, said: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* @internal A part printed on its side: its section in (y, z) of the fitted frame (as X, Y) extruded w along the slot
|
|
9
|
+
* (Z), a tongue into the slot under it, and holes square to the face, each a teardrop with its point cut flat just over
|
|
10
|
+
* the round so a head's seat is whole. holes: { thread, y, top, kind }, from the face at height top down through the
|
|
11
|
+
* part and its tongue, or { thread, y, depth, kind, from: 'face' }, a blind hole up from the contact face; pockets: { y, top, d, depth }, round pockets from the face at height top.
|
|
12
|
+
* @param {{ loop: number[][], width: number, tongue?: object, holes?: object[], pockets?: object[], pr: object, ops?: object }} o
|
|
13
|
+
* @returns {object} a JSCAD geom3 in its print pose
|
|
14
|
+
*/
|
|
15
|
+
export function sidePart({ loop, width, tongue, holes, pockets, pr, ops }: {
|
|
16
|
+
loop: number[][];
|
|
17
|
+
width: number;
|
|
18
|
+
tongue?: object;
|
|
19
|
+
holes?: object[];
|
|
20
|
+
pockets?: object[];
|
|
21
|
+
pr: object;
|
|
22
|
+
ops?: object;
|
|
23
|
+
}): object;
|
|
24
|
+
/** @internal A finished part's volume and grams from its solid. @param {object} m @param {object} solid @param {number} density @returns {void} */
|
|
25
|
+
export function weigh(m: object, solid: object, density: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {{ kind: 'panel', name: string, title: string, sheet: string, thickness: number, size: number[], corner: number, area: number, grams: number, holes: { thread: string, at: number[], diameter: number }[],
|
|
28
|
+
* findings: object[], rests: object[] }} Panel
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* A panel: a sheet of a material and thickness cut to a size, its corners rounded, with holes where screws pass. Its
|
|
32
|
+
* mass is the sheet's density times its volume less the holes. A thickness no stockist commonly holds is a warning.
|
|
33
|
+
* @param {string} sheet acrylic, polycarbonate or aluminium @param {number} thickness mm
|
|
34
|
+
* @param {{ size: number[], corner?: number, holes?: { thread: string, at: number[] }[], printer?: object }} o size: [x, y] in mm; holes at [x, y] from the panel's corner
|
|
35
|
+
* @returns {Panel}
|
|
36
|
+
*/
|
|
37
|
+
export function panelModel(sheet: string, thickness: number, o?: {
|
|
38
|
+
size: number[];
|
|
39
|
+
corner?: number;
|
|
40
|
+
holes?: {
|
|
41
|
+
thread: string;
|
|
42
|
+
at: number[];
|
|
43
|
+
}[];
|
|
44
|
+
printer?: object;
|
|
45
|
+
}): Panel;
|
|
46
|
+
/**
|
|
47
|
+
* A panel's solid: the sheet from [0, 0] to its size on x and y, z from 0 to its thickness, its corners rounded and its
|
|
48
|
+
* holes cut. @param {Panel} m panelModel's @param {{ printer?: object, ops?: object }} [o] ops: booleans to cut with, JSCAD's where left out
|
|
49
|
+
* @returns {object} a JSCAD geom3, with .model
|
|
50
|
+
*/
|
|
51
|
+
export function panel(m: Panel, o?: {
|
|
52
|
+
printer?: object;
|
|
53
|
+
ops?: object;
|
|
54
|
+
}): object;
|
|
55
|
+
/**
|
|
56
|
+
* A printed clip that holds a panel's edge down on a beam's face: a block on the face, screwed into a slot nut on the
|
|
57
|
+
* slot's centre line, keyed into the slot by a tongue, reaching over the panel's edge with a step as deep as the sheet.
|
|
58
|
+
* Sized from a named load (the panel pushed out at the clip) by beam formulas to about twice the margin; then made
|
|
59
|
+
* thick enough that a screw sold engages its nut and stops short of the slot's floor. It prints on its side.
|
|
60
|
+
* @param {string | object} profile @param {{ sheet: number, face?: string, thread?: string, head?: 'cap' | 'button', nut?: string, load?: number, grip?: number, printer?: object, material?: string | object, given?: object }} o
|
|
61
|
+
* sheet: the panel's thickness; grip: how far it reaches over the panel (default PANEL_DEFAULTS.grip)
|
|
62
|
+
* @returns {object} the clip's model: edge (where the panel's edge goes, from the slot's centre line), height, screws, grams, margin, findings
|
|
63
|
+
*/
|
|
64
|
+
export function panelClipModel(profile: string | object, o?: {
|
|
65
|
+
sheet: number;
|
|
66
|
+
face?: string;
|
|
67
|
+
thread?: string;
|
|
68
|
+
head?: "cap" | "button";
|
|
69
|
+
nut?: string;
|
|
70
|
+
load?: number;
|
|
71
|
+
grip?: number;
|
|
72
|
+
printer?: object;
|
|
73
|
+
material?: string | object;
|
|
74
|
+
given?: object;
|
|
75
|
+
}): object;
|
|
76
|
+
/**
|
|
77
|
+
* A panel clip's solid, from panelClipModel's model: on its side to print (pose 'print'), or fitted (pose 'fit').
|
|
78
|
+
* tongues: false leaves the tongue off; ops: booleans to join and cut with.
|
|
79
|
+
* @param {object} m @param {{ pose?: 'print' | 'fit', tongues?: boolean, ops?: object, printer?: object }} [o] @returns {object} a JSCAD geom3, with .model
|
|
80
|
+
*/
|
|
81
|
+
export function panelClip(m: object, o?: {
|
|
82
|
+
pose?: "print" | "fit";
|
|
83
|
+
tongues?: boolean;
|
|
84
|
+
ops?: object;
|
|
85
|
+
printer?: object;
|
|
86
|
+
}): object;
|
|
87
|
+
/**
|
|
88
|
+
* A printed corner piece over a panel's corner where two beams meet: an L on both beams' faces, a screw into each slot
|
|
89
|
+
* past the crossing, a step as deep as the sheet over the panel's corner, rounded where the panel's corner sits.
|
|
90
|
+
* Its frame: the two slots' centre lines along x and y, crossing at the origin, the panel's corner toward +x +y, z out
|
|
91
|
+
* of the faces. It prints its top face down.
|
|
92
|
+
* @param {string | object} profile @param {{ sheet: number, face?: string, thread?: string, head?: 'cap' | 'button', nut?: string, load?: number, grip?: number, printer?: object, material?: string | object, given?: object }} o
|
|
93
|
+
* @returns {object} the corner's model
|
|
94
|
+
*/
|
|
95
|
+
export function panelCornerModel(profile: string | object, o?: {
|
|
96
|
+
sheet: number;
|
|
97
|
+
face?: string;
|
|
98
|
+
thread?: string;
|
|
99
|
+
head?: "cap" | "button";
|
|
100
|
+
nut?: string;
|
|
101
|
+
load?: number;
|
|
102
|
+
grip?: number;
|
|
103
|
+
printer?: object;
|
|
104
|
+
material?: string | object;
|
|
105
|
+
given?: object;
|
|
106
|
+
}): object;
|
|
107
|
+
/**
|
|
108
|
+
* A panel corner's solid: top face down to print (pose 'print'), or fitted (pose 'fit').
|
|
109
|
+
* @param {object} m @param {{ pose?: 'print' | 'fit', tongues?: boolean, ops?: object, printer?: object }} [o] @returns {object} a JSCAD geom3, with .model
|
|
110
|
+
*/
|
|
111
|
+
export function panelCorner(m: object, o?: {
|
|
112
|
+
pose?: "print" | "fit";
|
|
113
|
+
tongues?: boolean;
|
|
114
|
+
ops?: object;
|
|
115
|
+
printer?: object;
|
|
116
|
+
}): object;
|
|
117
|
+
/**
|
|
118
|
+
* A printed cover that closes a slot nothing uses: a thin flange on the face, a stem in the slot's opening and a barb
|
|
119
|
+
* under each lip, leaning 45° so it prints. It prints lying down, its flange on the bed.
|
|
120
|
+
* @param {string | object} profile @param {{ length: number, face?: string, printer?: object, material?: string | object, given?: object }} o
|
|
121
|
+
* @returns {object} its model
|
|
122
|
+
*/
|
|
123
|
+
export function slotCoverModel(profile: string | object, o?: {
|
|
124
|
+
length: number;
|
|
125
|
+
face?: string;
|
|
126
|
+
printer?: object;
|
|
127
|
+
material?: string | object;
|
|
128
|
+
given?: object;
|
|
129
|
+
}): object;
|
|
130
|
+
/** A slot cover's solid: flange down to print (pose 'print'), or fitted (pose 'fit'). @param {object} m @param {{ pose?: 'print' | 'fit' }} [o] @returns {object} */
|
|
131
|
+
export function slotCover(m: object, o?: {
|
|
132
|
+
pose?: "print" | "fit";
|
|
133
|
+
}): object;
|
|
134
|
+
/**
|
|
135
|
+
* A printed edge that holds a sheet thinner than a slot's opening in the slot: a channel as wide as the opening less
|
|
136
|
+
* the fit, a groove as wide as the sheet with the fit, as deep as the lip and the cavity allow. Refused by name where
|
|
137
|
+
* the sheet leaves walls thinner than the printer's lines allow. It prints lying down, its groove up.
|
|
138
|
+
* @param {string | object} profile @param {{ sheet: number, length: number, face?: string, printer?: object, material?: string | object, given?: object }} o
|
|
139
|
+
* @returns {object} its model: depth (how far the sheet goes into the slot past the face)
|
|
140
|
+
*/
|
|
141
|
+
export function panelEdgeModel(profile: string | object, o?: {
|
|
142
|
+
sheet: number;
|
|
143
|
+
length: number;
|
|
144
|
+
face?: string;
|
|
145
|
+
printer?: object;
|
|
146
|
+
material?: string | object;
|
|
147
|
+
given?: object;
|
|
148
|
+
}): object;
|
|
149
|
+
/** An in-slot panel edge's solid: floor down to print, or fitted. @param {object} m @param {{ pose?: 'print' | 'fit' }} [o] @returns {object} */
|
|
150
|
+
export function panelEdge(m: object, o?: {
|
|
151
|
+
pose?: "print" | "fit";
|
|
152
|
+
}): object;
|
|
153
|
+
/**
|
|
154
|
+
* A printed gasket strip for a door's gap: a hollow triangle of thin walls, its base taped to the door's inner face,
|
|
155
|
+
* as high as the gap and the squeeze, so the closing door presses it onto the beam's face. Its walls lean 30° from
|
|
156
|
+
* upright, so it prints lying on its base and folds rather than buckles. Best in PETG, which springs back where PLA creeps.
|
|
157
|
+
* @param {{ gap: number, length: number, squeeze?: number, printer?: object, material?: string | object }} o
|
|
158
|
+
* @returns {object} its model: strain (its walls' at the squeeze) against the plastic's limit
|
|
159
|
+
*/
|
|
160
|
+
export function gasketStripModel(o?: {
|
|
161
|
+
gap: number;
|
|
162
|
+
length: number;
|
|
163
|
+
squeeze?: number;
|
|
164
|
+
printer?: object;
|
|
165
|
+
material?: string | object;
|
|
166
|
+
}): object;
|
|
167
|
+
/** A gasket strip's solid, base down (its print pose and, turned over onto the door, its fitted one). @param {object} m @returns {object} */
|
|
168
|
+
export function gasketStrip(m: object): object;
|
|
169
|
+
/**
|
|
170
|
+
* The sheets a panel is cut from, each with its density (from the maker's data sheet) and the thicknesses stockists
|
|
171
|
+
* commonly hold.
|
|
172
|
+
* @type {Record<string, { what: string, density: object, thicknesses: object }>}
|
|
173
|
+
*/
|
|
174
|
+
export const SHEETS: Record<string, {
|
|
175
|
+
what: string;
|
|
176
|
+
density: object;
|
|
177
|
+
thicknesses: object;
|
|
178
|
+
}>;
|
|
179
|
+
export namespace PANEL_DEFAULTS {
|
|
180
|
+
namespace gap {
|
|
181
|
+
export { text as rule };
|
|
182
|
+
export { kind };
|
|
183
|
+
export { source };
|
|
184
|
+
export { CHECKED as checked };
|
|
185
|
+
export { unit };
|
|
186
|
+
export { value };
|
|
187
|
+
}
|
|
188
|
+
namespace grip { }
|
|
189
|
+
namespace load { }
|
|
190
|
+
namespace pitch { }
|
|
191
|
+
namespace corner { }
|
|
192
|
+
namespace walls { }
|
|
193
|
+
namespace barb { }
|
|
194
|
+
namespace lap { }
|
|
195
|
+
namespace squeeze { }
|
|
196
|
+
}
|
|
197
|
+
export function bendT(M: number, b: number, S: number, k: number): number;
|
|
198
|
+
export function bendMargin(M: number, b: number, h: number, S: number): number;
|
|
199
|
+
export function sideToFit(w: number): number[];
|
|
200
|
+
export { closing as closingFindings };
|
|
201
|
+
export type Panel = {
|
|
202
|
+
kind: "panel";
|
|
203
|
+
name: string;
|
|
204
|
+
title: string;
|
|
205
|
+
sheet: string;
|
|
206
|
+
thickness: number;
|
|
207
|
+
size: number[];
|
|
208
|
+
corner: number;
|
|
209
|
+
area: number;
|
|
210
|
+
grams: number;
|
|
211
|
+
holes: {
|
|
212
|
+
thread: string;
|
|
213
|
+
at: number[];
|
|
214
|
+
diameter: number;
|
|
215
|
+
}[];
|
|
216
|
+
findings: object[];
|
|
217
|
+
rests: object[];
|
|
218
|
+
};
|
|
219
|
+
declare const CHECKED: "2026-11-17";
|
|
220
|
+
declare function closing(m: any, { S, sizeText, marginText, pose }: {
|
|
221
|
+
S: any;
|
|
222
|
+
sizeText: any;
|
|
223
|
+
marginText: any;
|
|
224
|
+
pose: any;
|
|
225
|
+
}): void;
|
package/panel.mjs
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
// Panels and the printed parts that hold them: a panel is a sheet (acrylic, polycarbonate, aluminium) by its material
|
|
2
|
+
// and thickness, cut to the bay of a frame it closes, with its mass from the sheet's density; a panel clip screws into
|
|
3
|
+
// a face's slot and holds the panel's edge down; a panel corner holds a corner over two beams; an in-slot panel edge
|
|
4
|
+
// holds a thinner sheet in a slot's opening; a slot cover closes a slot nothing uses; a gasket strip seals a door's
|
|
5
|
+
// gap. Each printed part is drawn from the profile's, the thread's and the printer's rules, prints without supports
|
|
6
|
+
// with a plain first layer, and reports its grams and its margin at a named load.
|
|
7
|
+
//
|
|
8
|
+
// A clip's frame (its fitted pose): x along the slot (0 at the clip's middle), y across it toward the panel (0 on the
|
|
9
|
+
// slot's centre line), z out of the beam's face (0 on the face). It prints on its side: its section in (y, z) is the
|
|
10
|
+
// first layer, the slot's direction up. A strip's frame: x along the slot from 0, y across, z out of the face; it
|
|
11
|
+
// prints lying down. Units: mm, N, grams.
|
|
12
|
+
import jscad from '@jscad/modeling';
|
|
13
|
+
import { hole, holeModel } from '@rulecad/fixings';
|
|
14
|
+
import { FITTING_DEFAULTS, printerOf, pfig, materialOf, options, profileOf, slotSide, roundConcave, ccw, combine, tongueLoop, sold, screwOf } from './fitting.mjs';
|
|
15
|
+
|
|
16
|
+
const { polygon, cuboid } = jscad.primitives, { extrudeLinear } = jscad.extrusions, { intersect, subtract } = jscad.booleans;
|
|
17
|
+
const { translate, transform } = jscad.transforms, { measureVolume } = jscad.measurements;
|
|
18
|
+
const CHECKED = '2026-11-17';
|
|
19
|
+
const isNum = (x) => typeof x === 'number' && Number.isFinite(x);
|
|
20
|
+
const shown = (v) => { const s = v === undefined ? 'nothing' : JSON.stringify(v) ?? String(v); return s.length > 80 ? `${s.slice(0, 77)}...` : s; };
|
|
21
|
+
const mm = (x) => String(+Number(x).toFixed(2));
|
|
22
|
+
const r3 = (x) => +x.toFixed(3);
|
|
23
|
+
const an = (t) => `${/^(M|[aeiou8])/i.test(String(t)) ? 'an' : 'a'} ${t}`; // (an M5, a 6-32)
|
|
24
|
+
const up = (x, step) => Math.ceil(x / step - 1e-9) * step;
|
|
25
|
+
const finding = (level, text, code, extra = {}) => ({ level, text, code, ...extra });
|
|
26
|
+
const rule = (value, unit, text, kind, source) => ({ value, ...(unit ? { unit } : {}), rule: text, kind, source, checked: CHECKED });
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The sheets a panel is cut from, each with its density (from the maker's data sheet) and the thicknesses stockists
|
|
30
|
+
* commonly hold.
|
|
31
|
+
* @type {Record<string, { what: string, density: object, thicknesses: object }>}
|
|
32
|
+
*/
|
|
33
|
+
export const SHEETS = {
|
|
34
|
+
acrylic: { what: 'cast acrylic (PMMA) sheet', density: rule(1.19, 'g/cm³', 'Cast acrylic sheet weighs 1.19 g/cm³', 'spec', 'Evonik PLEXIGLAS GS technical information: density 1.19 g/cm³ by ISO 1183'),
|
|
35
|
+
thicknesses: rule([2, 3, 4, 5, 6, 8, 10], 'mm', 'Thicknesses stockists commonly cut cast acrylic from', 'community', 'Stockists\' lists of cast acrylic sheet, not one maker\'s range: check your supplier') },
|
|
36
|
+
polycarbonate: { what: 'solid polycarbonate sheet', density: rule(1.2, 'g/cm³', 'Solid polycarbonate sheet weighs 1.20 g/cm³', 'spec', 'Covestro Makrolon GP / Exolon GP technical data sheet: density 1200 kg/m³ by ISO 1183-1'),
|
|
37
|
+
thicknesses: rule([1, 2, 3, 4, 5, 6], 'mm', 'Thicknesses stockists commonly cut solid polycarbonate from', 'community', 'Stockists\' lists of solid polycarbonate sheet, not one maker\'s range: check your supplier') },
|
|
38
|
+
aluminium: { what: 'aluminium sheet, EN AW-5754', density: rule(2.66, 'g/cm³', 'EN AW-5754 aluminium sheet weighs 2.66 g/cm³', 'spec', 'Aalco data sheet, aluminium alloy 5754 H26 sheet: density 2.66 g/cm³'),
|
|
39
|
+
thicknesses: rule([1, 1.5, 2, 3], 'mm', 'Thicknesses stockists commonly cut 5754 sheet from', 'community', 'Stockists\' lists of 5754 sheet, not one maker\'s range: check your supplier') },
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** The working figures of panels and their printed parts, each with what it rests on. */
|
|
43
|
+
export const PANEL_DEFAULTS = {
|
|
44
|
+
gap: rule(0.5, 'mm', 'Room between a panel\'s cut edge and the printed part it lies against: the cut\'s tolerance', 'estimate', 'A working figure of @rulecad/frames: a laser or saw cut to about ±0.2 mm, with room over'),
|
|
45
|
+
grip: rule(6, 'mm', 'How far a clip reaches over the panel\'s edge', 'estimate', 'A working figure of @rulecad/frames'),
|
|
46
|
+
load: rule(30, 'N', 'The design load on one clip where none is given: the panel pushed out by a hand, its share at one clip', 'default', 'A working figure of @rulecad/frames, so every clip is sized and compared at one named load'),
|
|
47
|
+
pitch: rule(150, 'mm', 'Clips along a panel\'s edge are no further apart than this, with one near each end', 'estimate', 'A working figure of @rulecad/frames: a 3 mm sheet between clips this far apart does not lift visibly at the clip\'s load'),
|
|
48
|
+
corner: rule(1, 'mm', 'A panel\'s corners are rounded this much, so they sit in a corner piece\'s rounded step', 'default', 'A working figure of @rulecad/frames'),
|
|
49
|
+
walls: rule(3, 'lines', 'A printed part\'s thinnest wall, in the printer\'s lines', 'default', 'A working figure of @rulecad/frames: three lines hold together where two may part'),
|
|
50
|
+
barb: rule(0.3, 'mm', 'How far a slot cover\'s barb reaches past the slot\'s opening under its lip', 'estimate', 'A working figure of @rulecad/frames, to be checked by a test print'),
|
|
51
|
+
lap: rule(1, 'mm', 'How far a slot cover\'s flange laps the face past the slot\'s opening on each side', 'default', 'A working figure of @rulecad/frames'),
|
|
52
|
+
squeeze: rule(0.5, 'mm', 'How far a door presses its gasket strip down when it closes', 'estimate', 'A working figure of @rulecad/frames'),
|
|
53
|
+
};
|
|
54
|
+
const want = () => FITTING_DEFAULTS.margin.value;
|
|
55
|
+
|
|
56
|
+
// ---------- shared ----------
|
|
57
|
+
/** @internal A bending member's least thickness for a margin: b wide, bent by M. @param {number} M @param {number} b @param {number} S @param {number} k @returns {number} */
|
|
58
|
+
export const bendT = (M, b, S, k) => Math.sqrt((6 * M * k) / (b * S));
|
|
59
|
+
/** @internal A bending member's margin: S over 6M / (b h²). @param {number} M @param {number} b @param {number} h @param {number} S @returns {number} */
|
|
60
|
+
export const bendMargin = (M, b, h, S) => S / ((6 * M) / (b * h * h));
|
|
61
|
+
/** @internal The common setup of a printed part: printer, plastic and their figures. @param {string} what @param {object} o @returns {any} */
|
|
62
|
+
export function partSetup(what, o) {
|
|
63
|
+
const pr = printerOf(what, o.printer), mat = materialOf(what, o.material ?? 'pla');
|
|
64
|
+
return { pr, mat, fit: pfig(pr, 'fit'), layer: pfig(pr, 'layer'), line: pfig(pr, 'line'), S: mat.rules.strength.value, density: mat.rules.density.value };
|
|
65
|
+
}
|
|
66
|
+
/** @internal A sheet's thickness, refused by name. @param {string} what @param {any} t @returns {number} */
|
|
67
|
+
export function sheetThickness(what, t) {
|
|
68
|
+
if (!(isNum(t) && t > 0 && t <= 20)) throw new Error(`${what}: sheet is the panel's thickness in mm, above 0 and up to 20 (got ${shown(t)})`);
|
|
69
|
+
return t;
|
|
70
|
+
}
|
|
71
|
+
/** @internal A load in N, refused by name. @param {string} what @param {any} F @param {string} said @returns {void} */
|
|
72
|
+
export function loadOk(what, F, said) { if (F != null && !(isNum(F) && F > 0)) throw new Error(`${what}: load is ${said}, in N, above 0 (got ${shown(F)})`); }
|
|
73
|
+
|
|
74
|
+
// A teardrop's outline about (0, 0) in (across, up), its point up at 45°
|
|
75
|
+
const teardrop = (r, n = 32) => [[0, r * Math.SQRT2], ...Array.from({ length: n + 1 }, (_, k) => { const a = Math.PI / 4 - (k * 3 * Math.PI) / (2 * n); return [r * Math.cos(a), r * Math.sin(a)]; })];
|
|
76
|
+
const prism = (loop, h) => extrudeLinear({ height: h }, polygon({ points: ccw(loop) }));
|
|
77
|
+
// print frame (X across, Y out of the face, Z along the slot from 0 to w) to the fitted frame (x along, y across, z out)
|
|
78
|
+
/** @internal The turn from a side-printed part's print frame to its fitted frame. @param {number} w @returns {number[]} */
|
|
79
|
+
export const sideToFit = (w) => [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, -w / 2, 0, 0, 1];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @internal A part printed on its side: its section in (y, z) of the fitted frame (as X, Y) extruded w along the slot
|
|
83
|
+
* (Z), a tongue into the slot under it, and holes square to the face, each a teardrop with its point cut flat just over
|
|
84
|
+
* the round so a head's seat is whole. holes: { thread, y, top, kind }, from the face at height top down through the
|
|
85
|
+
* part and its tongue, or { thread, y, depth, kind, from: 'face' }, a blind hole up from the contact face; pockets: { y, top, d, depth }, round pockets from the face at height top.
|
|
86
|
+
* @param {{ loop: number[][], width: number, tongue?: object, holes?: object[], pockets?: object[], pr: object, ops?: object }} o
|
|
87
|
+
* @returns {object} a JSCAD geom3 in its print pose
|
|
88
|
+
*/
|
|
89
|
+
export function sidePart({ loop, width, tongue = null, holes = [], pockets = [], pr, ops = null }) {
|
|
90
|
+
const root = pfig(pr, 'fit'), parts = [prism(loop, width)], c = width / 2;
|
|
91
|
+
if (tongue && tongue.depth > 0) parts.push(prism(tongueLoop(tongue.at - tongue.width / 2, tongue.at + tongue.width / 2, tongue.depth, false, root).map(([n, a]) => [a, -n]), width));
|
|
92
|
+
const deep = (top) => top + (tongue?.depth ?? 0) + 2;
|
|
93
|
+
const cuts = holes.map((h) => {
|
|
94
|
+
const g = h.from === 'face' ? hole(h.thread, { kind: h.kind ?? 'pilot', into: '+y', depth: h.depth + 1, at: [h.y, -1, c], printer: pr }) : hole(h.thread, { kind: h.kind ?? 'clearance', into: '-y', depth: deep(h.top), at: [h.y, h.top + 1, c], printer: pr }), r = g.model.diameter / 2;
|
|
95
|
+
return intersect(g, cuboid({ size: [4 * width + 200, 4 * (h.top ?? h.depth) + 200, c + 1.02 * r + 1], center: [h.y, 0, (c + 1.02 * r - 1) / 2] }));
|
|
96
|
+
});
|
|
97
|
+
for (const p of pockets) cuts.push(translate([p.y, p.top + 1, c], transform([1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1], prism(teardrop(p.d / 2), p.depth + 1)))); // (u, v) to (X, Z), down along -Y
|
|
98
|
+
return combine(parts, cuts, ops);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The kit's findings every printed part ends with: its size, its margin at its named load, how it prints, its mass
|
|
102
|
+
function closing(m, { S, sizeText, marginText, pose }) {
|
|
103
|
+
const ok = m.margin >= want() - 1e-9;
|
|
104
|
+
m.findings.push(finding('info', `${m.title}: ${sizeText}`, 'fitting.size', { values: { ...m.size } }));
|
|
105
|
+
m.findings.push(finding(ok ? 'pass' : 'fail', `${marginText}, ${mm(m.margin)} times under ${m.material.toUpperCase()}'s ${S} MPa (${ok ? `within the ${want()}× asked` : `short of the ${want()}× asked`}): by beam formulas, an estimate`, 'fitting.margin', { values: { load: m.load.force, stress: m.stress, strength: S, margin: m.margin } }));
|
|
106
|
+
m.findings.push(finding('info', `it is drawn to print ${pose}: a plain first layer, no supports (printcheck's check() reads the solid)`, 'fitting.printable', { values: { pose } }));
|
|
107
|
+
m.findings.push(finding('info', `it weighs ${mm(m.grams)} g of ${m.material} (${mm(m.volume)} mm³)`, 'fitting.mass', { values: { grams: m.grams, volume: m.volume } }));
|
|
108
|
+
}
|
|
109
|
+
/** @internal A finished part's volume and grams from its solid. @param {object} m @param {object} solid @param {number} density @returns {void} */
|
|
110
|
+
export function weigh(m, solid, density) { m.volume = r3(measureVolume(solid)); m.grams = r3((m.volume * density) / 1000); }
|
|
111
|
+
/** @internal The closing findings, shared with the door's and the ends' parts. */
|
|
112
|
+
export { closing as closingFindings };
|
|
113
|
+
const screwFinding = (m, fits, sc) => m.findings.push(fits
|
|
114
|
+
? finding('pass', `${sc.thread}x${fits.lengths[0]} ${sc.head}: through ${mm(fits.t)} mm of ${m.fitting.replace('-', ' ')}, its tip ${mm(fits.lengths[0] - fits.t)} mm under the face, between ${mm(fits.windows[0].lo)} (its nut's thread engaged) and ${mm(fits.windows[0].hi)} (the slot's floor less ${FITTING_DEFAULTS.floor.value} mm)`, 'fitting.screw', { values: { lengths: fits.lengths, windows: fits.windows } })
|
|
115
|
+
: finding('warn', `no ${sc.thread} ${sc.head} screw sold engages its slot nut fully and stops short of the slot's floor here: the screw's length is the fasten check's to choose`, 'fitting.screw', {}));
|
|
116
|
+
const tongueFinding = (m, sd, pr) => m.findings.push(finding(sd.tongue.depth > 0 ? 'pass' : 'info', sd.tongue.depth > 0 ? `its tongue keys into ${sd.slot.name}: ${mm(sd.tongue.width)} mm wide (the ${mm(sd.slot.opening)} mm opening less ${pr.name}'s fit each side), ${mm(sd.tongue.depth)} mm deep (the lip less ${an(sd.thread)} slot nut's tongue, less the fit)` : `${sd.slot.name}'s lip leaves no room for a tongue over ${an(sd.thread)} slot nut: it lies flat on the face`, 'fitting.tongue', { values: { ...sd.tongue }, refs: { slot: sd.slot.name, nut: sd.nut.name } }));
|
|
117
|
+
const short = (p) => p.name.replace(/^profile-/, '');
|
|
118
|
+
|
|
119
|
+
// ---------- a panel ----------
|
|
120
|
+
/**
|
|
121
|
+
* @typedef {{ kind: 'panel', name: string, title: string, sheet: string, thickness: number, size: number[], corner: number, area: number, grams: number, holes: { thread: string, at: number[], diameter: number }[],
|
|
122
|
+
* findings: object[], rests: object[] }} Panel
|
|
123
|
+
*/
|
|
124
|
+
/**
|
|
125
|
+
* A panel: a sheet of a material and thickness cut to a size, its corners rounded, with holes where screws pass. Its
|
|
126
|
+
* mass is the sheet's density times its volume less the holes. A thickness no stockist commonly holds is a warning.
|
|
127
|
+
* @param {string} sheet acrylic, polycarbonate or aluminium @param {number} thickness mm
|
|
128
|
+
* @param {{ size: number[], corner?: number, holes?: { thread: string, at: number[] }[], printer?: object }} o size: [x, y] in mm; holes at [x, y] from the panel's corner
|
|
129
|
+
* @returns {Panel}
|
|
130
|
+
*/
|
|
131
|
+
export function panelModel(sheet, thickness, o = {}) {
|
|
132
|
+
const what = 'panelModel';
|
|
133
|
+
const s = SHEETS[String(sheet).toLowerCase()];
|
|
134
|
+
if (!s) throw new Error(`${what}: sheet is one of ${Object.keys(SHEETS).join(', ')} (got ${shown(sheet)})`);
|
|
135
|
+
options(what, o, ['size', 'corner', 'holes', 'printer']);
|
|
136
|
+
const T = sheetThickness(what, thickness);
|
|
137
|
+
if (!(Array.isArray(o.size) && o.size.length === 2 && o.size.every((x) => isNum(x) && x > 0))) throw new Error(`${what}: size is [x, y] in mm, each above 0 (got ${shown(o.size)})`);
|
|
138
|
+
const corner = o.corner ?? PANEL_DEFAULTS.corner.value;
|
|
139
|
+
if (!(isNum(corner) && corner >= 0 && corner < Math.min(...o.size) / 2)) throw new Error(`${what}: corner is the corners' radius in mm, from 0 to under half the panel's least side (got ${shown(o.corner)})`);
|
|
140
|
+
const pr = printerOf(what, o.printer);
|
|
141
|
+
const holes = (o.holes ?? []).map((h, i) => {
|
|
142
|
+
if (!h || typeof h.thread !== 'string' || !(Array.isArray(h.at) && h.at.length === 2 && h.at.every(isNum))) throw new Error(`${what}: hole ${i + 1} is { thread: 'M3', at: [x, y] } (got ${shown(h)})`);
|
|
143
|
+
const d = holeModel(h.thread, { kind: 'clearance', printer: pr }).diameter;
|
|
144
|
+
if (h.at[0] < d / 2 || h.at[1] < d / 2 || h.at[0] > o.size[0] - d / 2 || h.at[1] > o.size[1] - d / 2) throw new Error(`${what}: hole ${i + 1} at [${h.at.map(mm).join(', ')}] is off the ${mm(o.size[0])} x ${mm(o.size[1])} mm panel`);
|
|
145
|
+
return { thread: h.thread, at: h.at.map(r3), diameter: d };
|
|
146
|
+
});
|
|
147
|
+
const [a, b] = o.size.map(r3), area = r3(a * b - (4 - Math.PI) * corner * corner - holes.reduce((t, h) => t + (Math.PI * h.diameter * h.diameter) / 4, 0));
|
|
148
|
+
const grams = r3((area * T * s.density.value) / 1000), name = `panel-${String(sheet).toLowerCase()}-${mm(T)}mm`;
|
|
149
|
+
const findings = [finding('info', `${mm(a)} x ${mm(b)} mm of ${mm(T)} mm ${s.what}, its corners rounded ${mm(corner)} mm${holes.length ? `, ${holes.length} hole${holes.length > 1 ? 's' : ''} for ${[...new Set(holes.map((h) => h.thread))].join(' and ')} screws` : ''}: ${mm(grams)} g`, 'panel.size', { values: { size: [a, b], thickness: T, grams, holes: holes.length } })];
|
|
150
|
+
const stocked = s.thicknesses.value.some((x) => Math.abs(x - T) < 1e-9);
|
|
151
|
+
findings.push(finding(stocked ? 'pass' : 'warn', stocked ? `${mm(T)} mm is a thickness ${sheet} is commonly stocked in (${s.thicknesses.kind})` : `${mm(T)} mm ${sheet} is not commonly stocked: ${s.thicknesses.value.join(', ')} mm are (${s.thicknesses.kind}, check your supplier)`, 'panel.thickness', { values: { thickness: T, stocked: s.thicknesses.value } }));
|
|
152
|
+
return { kind: 'panel', name, title: `${mm(T)} mm ${sheet} panel, ${mm(a)} x ${mm(b)} mm`, sheet: String(sheet).toLowerCase(), thickness: T, size: [a, b], corner, area, grams, holes, findings,
|
|
153
|
+
rests: [{ name: `SHEETS.${sheet}.density`, value: s.density.value, kind: s.density.kind }, { name: 'PANEL_DEFAULTS.corner', value: corner, kind: PANEL_DEFAULTS.corner.kind }] };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A panel's solid: the sheet from [0, 0] to its size on x and y, z from 0 to its thickness, its corners rounded and its
|
|
158
|
+
* holes cut. @param {Panel} m panelModel's @param {{ printer?: object, ops?: object }} [o] ops: booleans to cut with, JSCAD's where left out
|
|
159
|
+
* @returns {object} a JSCAD geom3, with .model
|
|
160
|
+
*/
|
|
161
|
+
export function panel(m, o = {}) {
|
|
162
|
+
if (m?.kind !== 'panel') throw new Error(`panel: give a panel's model (panelModel), not ${shown(m)}`);
|
|
163
|
+
const [a, b] = m.size, r = m.corner, pr = printerOf('panel', o.printer);
|
|
164
|
+
const out = r > 0 ? roundConcave(ccw([[0, 0], [a, 0], [a, b], [0, b]]).reverse(), r).reverse() : [[0, 0], [a, 0], [a, b], [0, b]];
|
|
165
|
+
const body = prism(out, m.thickness), cuts = m.holes.map((h) => hole(h.thread, { kind: 'clearance', into: '-z', depth: m.thickness + 2, at: [h.at[0], h.at[1], m.thickness + 1], printer: pr }));
|
|
166
|
+
return Object.assign(cuts.length ? (o.ops ? o.ops.subtract(body, ...cuts) : subtract(body, ...cuts)) : body, { model: m });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ---------- a panel clip ----------
|
|
170
|
+
/**
|
|
171
|
+
* A printed clip that holds a panel's edge down on a beam's face: a block on the face, screwed into a slot nut on the
|
|
172
|
+
* slot's centre line, keyed into the slot by a tongue, reaching over the panel's edge with a step as deep as the sheet.
|
|
173
|
+
* Sized from a named load (the panel pushed out at the clip) by beam formulas to about twice the margin; then made
|
|
174
|
+
* thick enough that a screw sold engages its nut and stops short of the slot's floor. It prints on its side.
|
|
175
|
+
* @param {string | object} profile @param {{ sheet: number, face?: string, thread?: string, head?: 'cap' | 'button', nut?: string, load?: number, grip?: number, printer?: object, material?: string | object, given?: object }} o
|
|
176
|
+
* sheet: the panel's thickness; grip: how far it reaches over the panel (default PANEL_DEFAULTS.grip)
|
|
177
|
+
* @returns {object} the clip's model: edge (where the panel's edge goes, from the slot's centre line), height, screws, grams, margin, findings
|
|
178
|
+
*/
|
|
179
|
+
export function panelClipModel(profile, o = {}) {
|
|
180
|
+
const what = 'panelClipModel';
|
|
181
|
+
options(what, o ?? {}, ['sheet', 'face', 'thread', 'head', 'nut', 'load', 'grip', 'printer', 'material', 'given']);
|
|
182
|
+
const T = sheetThickness(what, o.sheet), given = o.given ?? {}, p = profileOf(what, profile, given), k = partSetup(what, o);
|
|
183
|
+
loadOk(what, o.load, 'the force pushing the panel out at one clip');
|
|
184
|
+
const head = o.head ?? 'button';
|
|
185
|
+
if (!['cap', 'button'].includes(head)) throw new Error(`${what}: head is cap or button (got ${shown(o.head)})`);
|
|
186
|
+
const grip = o.grip ?? PANEL_DEFAULTS.grip.value;
|
|
187
|
+
if (!(isNum(grip) && grip > 0)) throw new Error(`${what}: grip is how far the clip reaches over the panel, in mm, above 0 (got ${shown(o.grip)})`);
|
|
188
|
+
const sd = slotSide(what, p, o.face ?? 'top', o.thread, o.nut, k.fit, given), sc = screwOf(what, sd.thread, head, k.pr);
|
|
189
|
+
const w = sd.cell, gap = PANEL_DEFAULTS.gap.value, e = r3(up(Math.max(FITTING_DEFAULTS.end.value * sc.hd, sc.dk / 2 + FITTING_DEFAULTS.reach.value), 0.5)), reach = r3(e + gap + grip);
|
|
190
|
+
const F = o.load ?? PANEL_DEFAULTS.load.value, M = F * (gap + grip / 2), least = up(PANEL_DEFAULTS.walls.value * k.line, k.layer);
|
|
191
|
+
const tc0 = Math.max(least, up(bendT(M, w, k.S, want()), k.layer)), fits = sold(r3(T + tc0), k.layer, [sd], sd.thread), H = fits ? fits.t : r3(T + tc0), tc = r3(H - T);
|
|
192
|
+
const stress = r3((6 * M) / (w * tc * tc)), margin = r3(k.S / stress);
|
|
193
|
+
const loop = roundConcave(ccw([[-e, 0], [e, 0], [e, T], [reach, T], [reach, H], [-e, H]]), gap, null, 8).map(([y, z]) => [r3(y), r3(z)]);
|
|
194
|
+
const m = { kind: 'fitting', fitting: 'panel-clip', name: `panel-clip-${short(p)}-${sd.thread.toLowerCase()}-${mm(T)}mm`, title: `printed panel clip for ${short(p)}, a ${mm(T)} mm sheet, ${sd.thread}`,
|
|
195
|
+
profile: p.name, face: sd.face, thread: sd.thread, head, sheet: T, width: w, height: H, thickness: tc, edge: r3(e + gap), grip, reach, section: loop,
|
|
196
|
+
tongue: { slot: sd.slot.name, ...sd.tongue, nut: sd.nut.name },
|
|
197
|
+
screws: [{ thread: sd.thread, head, grip: H, at: [0, 0, H], axis: [0, 0, -1], nut: sd.nut.name, nutKind: sd.nut.nutKind, length: fits?.lengths[0] ?? null }],
|
|
198
|
+
load: { force: F, what: `${F} N pushing the panel out at the clip, ${mm(gap + grip / 2)} mm past its step` }, stress, margin, size: { width: w, height: H, thickness: tc, edge: r3(e + gap), grip },
|
|
199
|
+
volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [],
|
|
200
|
+
rests: [{ name: `${k.mat.name}.strength`, value: k.S }, ...['gap', 'grip', 'load', 'walls'].map((x) => ({ name: `PANEL_DEFAULTS.${x}`, value: PANEL_DEFAULTS[x].value, kind: PANEL_DEFAULTS[x].kind }))] };
|
|
201
|
+
weigh(m, panelClip(m, { printer: k.pr }), k.density);
|
|
202
|
+
tongueFinding(m, sd, k.pr); screwFinding(m, fits, sc);
|
|
203
|
+
closing(m, { S: k.S, sizeText: `${mm(H)} mm high over the face, ${mm(tc)} mm over the panel, ${mm(w)} mm wide; the panel's edge ${mm(e + gap)} mm from the slot's centre line, held ${mm(grip)} mm in`, marginText: `under ${m.load.what}, the step's root bends to ${mm(stress)} MPa`, pose: 'on its side, its section the first layer' });
|
|
204
|
+
return m;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* A panel clip's solid, from panelClipModel's model: on its side to print (pose 'print'), or fitted (pose 'fit').
|
|
209
|
+
* tongues: false leaves the tongue off; ops: booleans to join and cut with.
|
|
210
|
+
* @param {object} m @param {{ pose?: 'print' | 'fit', tongues?: boolean, ops?: object, printer?: object }} [o] @returns {object} a JSCAD geom3, with .model
|
|
211
|
+
*/
|
|
212
|
+
export function panelClip(m, o = {}) {
|
|
213
|
+
if (m?.fitting !== 'panel-clip') throw new Error(`panelClip: give a clip's model (panelClipModel), not ${shown(m)}`);
|
|
214
|
+
const pr = printerOf('panelClip', o.printer), g = sidePart({ loop: m.section, width: m.width, tongue: o.tongues === false ? null : { at: 0, ...m.tongue }, holes: [{ thread: m.thread, y: 0, top: m.height }], pr, ops: o.ops });
|
|
215
|
+
return Object.assign(o.pose === 'fit' ? transform(sideToFit(m.width), g) : g, { model: m });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ---------- a panel corner ----------
|
|
219
|
+
/**
|
|
220
|
+
* A printed corner piece over a panel's corner where two beams meet: an L on both beams' faces, a screw into each slot
|
|
221
|
+
* past the crossing, a step as deep as the sheet over the panel's corner, rounded where the panel's corner sits.
|
|
222
|
+
* Its frame: the two slots' centre lines along x and y, crossing at the origin, the panel's corner toward +x +y, z out
|
|
223
|
+
* of the faces. It prints its top face down.
|
|
224
|
+
* @param {string | object} profile @param {{ sheet: number, face?: string, thread?: string, head?: 'cap' | 'button', nut?: string, load?: number, grip?: number, printer?: object, material?: string | object, given?: object }} o
|
|
225
|
+
* @returns {object} the corner's model
|
|
226
|
+
*/
|
|
227
|
+
export function panelCornerModel(profile, o = {}) {
|
|
228
|
+
const what = 'panelCornerModel';
|
|
229
|
+
options(what, o ?? {}, ['sheet', 'face', 'thread', 'head', 'nut', 'load', 'grip', 'printer', 'material', 'given']);
|
|
230
|
+
const clip = panelClipModel(profile, { ...o }), k = partSetup(what, o), p = profileOf(what, profile, o.given ?? {});
|
|
231
|
+
const half = Math.max(p.width, p.height) / 2, nutLen = Math.max(...slotSide(what, p, o.face ?? 'top', clip.thread, o.nut, k.fit, o.given ?? {}).nuts.map((n) => n.length));
|
|
232
|
+
const sc = screwOf(what, clip.thread, clip.head, k.pr), s = r3(up(Math.max(half + nutLen / 2 + k.fit, clip.reach + sc.dk / 2), 0.5)), end = r3(up(s + clip.edge - PANEL_DEFAULTS.gap.value, 0.5));
|
|
233
|
+
const e = clip.edge - PANEL_DEFAULTS.gap.value, R = clip.reach;
|
|
234
|
+
const outline = roundConcave(ccw([[-e, -e], [end, -e], [end, R], [R, R], [R, end], [-e, end]]), Math.min(R - e, 3), null, 10).map(([x, y]) => [r3(x), r3(y)]);
|
|
235
|
+
// the clip's load at the corner, on the step along both edges near it (two grips long): sized as a clip is
|
|
236
|
+
const F = clip.load.force, M = F * (PANEL_DEFAULTS.gap.value + clip.grip / 2), b = 2 * clip.grip, tc0 = Math.max(clip.thickness, up(bendT(M, b, k.S, want()), k.layer));
|
|
237
|
+
const sd = slotSide(what, p, o.face ?? 'top', clip.thread, o.nut, k.fit, o.given ?? {}), fits = sold(r3(clip.sheet + tc0), k.layer, [sd], clip.thread), H = fits ? fits.t : r3(clip.sheet + tc0), T = clip.sheet;
|
|
238
|
+
const stress = r3((6 * M) / (b * (H - T) ** 2)), margin = r3(k.S / stress);
|
|
239
|
+
const m = { kind: 'fitting', fitting: 'panel-corner', name: clip.name.replace('panel-clip', 'panel-corner'), title: clip.title.replace('panel clip', 'panel corner'), profile: clip.profile, face: clip.face, thread: clip.thread, head: clip.head,
|
|
240
|
+
sheet: T, height: H, thickness: r3(H - T), edge: clip.edge, outline, arm: end, round: PANEL_DEFAULTS.corner.value, tongue: clip.tongue, cross: half,
|
|
241
|
+
screws: [[s, 0], [0, s]].map(([x, y]) => ({ ...clip.screws[0], grip: H, at: [x, y, H], length: fits?.lengths[0] ?? null })), load: { force: F, what: `${F} N pushing the panel's corner out` }, stress, margin, size: { arm: end, height: H, edge: clip.edge },
|
|
242
|
+
volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [], rests: clip.rests };
|
|
243
|
+
weigh(m, panelCorner(m, { printer: k.pr }), k.density);
|
|
244
|
+
closing(m, { S: k.S, sizeText: `arms ${mm(end)} mm along each slot from the crossing, ${mm(H)} mm high, its screws ${mm(s)} mm along each slot, clear of the other beam`, marginText: `under ${m.load.what}, the step bends to ${mm(stress)} MPa`, pose: 'top face down, its step and tongues up' });
|
|
245
|
+
return m;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* A panel corner's solid: top face down to print (pose 'print'), or fitted (pose 'fit').
|
|
250
|
+
* @param {object} m @param {{ pose?: 'print' | 'fit', tongues?: boolean, ops?: object, printer?: object }} [o] @returns {object} a JSCAD geom3, with .model
|
|
251
|
+
*/
|
|
252
|
+
export function panelCorner(m, o = {}) {
|
|
253
|
+
if (m?.fitting !== 'panel-corner') throw new Error(`panelCorner: give a corner's model (panelCornerModel), not ${shown(m)}`);
|
|
254
|
+
const pr = printerOf('panelCorner', o.printer), root = pfig(pr, 'fit'), H = m.height, T = m.sheet, e = m.edge - PANEL_DEFAULTS.gap.value, big = m.arm + 10;
|
|
255
|
+
// in the print frame: y = -y(fit), z = H - z(fit), so the contact face is on top at z = H and the step opens up
|
|
256
|
+
const flip = (pts) => pts.map(([x, y]) => [x, -y]), parts = [prism(flip(m.outline), H)];
|
|
257
|
+
if (o.tongues !== false && m.tongue.depth > 0) {
|
|
258
|
+
const tl = tongueLoop(-m.tongue.width / 2, m.tongue.width / 2, m.tongue.depth, false, root), from = m.cross + root, len = m.arm - root - from;
|
|
259
|
+
parts.push(transform([0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, from, 0, 0, 1], prism(tl.map(([n, a]) => [a, H + n]), len))); // along x: (a, H + n) in (Y, Z)
|
|
260
|
+
parts.push(transform([0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -(from + len), 0, 1], prism(tl.map(([n, a]) => [H + n, a]), len))); // along -y: (H + n, a) in (Z, X)
|
|
261
|
+
}
|
|
262
|
+
// the step over the panel: x > e and y > e (fitted), its corner at (e, e) rounded where the panel's rounded corner sits
|
|
263
|
+
const rr = m.round + PANEL_DEFAULTS.gap.value, arc = Array.from({ length: 13 }, (_, i) => { const t = Math.PI + (i / 12) * (Math.PI / 2); return [e + rr + rr * Math.cos(t), e + rr + rr * Math.sin(t)]; });
|
|
264
|
+
const step = translate([0, 0, H - T], prism(flip([[big, e], [big, big], [e, big], ...arc]), T + 1));
|
|
265
|
+
const holes = m.screws.map((q) => hole(m.thread, { kind: 'clearance', into: '+z', depth: H + 2 + m.tongue.depth, at: [q.at[0], -q.at[1], -1], printer: pr }));
|
|
266
|
+
const g = combine(parts, [step, ...holes], o.ops);
|
|
267
|
+
return Object.assign(o.pose === 'fit' ? transform([1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, H, 1], g) : g, { model: m });
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ---------- strips: a slot cover, an in-slot panel edge, a gasket ----------
|
|
271
|
+
// A strip's section in (y, z) of its fitted frame, extruded along x for its length (pose 'fit'); to print, turned over
|
|
272
|
+
// onto its top (bed 'top') or lifted onto its lowest face (bed 'bottom'), lying along the bed
|
|
273
|
+
function stripSolid(loop, length, bed, pose) {
|
|
274
|
+
const fit = transform([0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1], prism(loop, length));
|
|
275
|
+
if (pose === 'fit') return fit;
|
|
276
|
+
const zs = loop.map((q) => q[1]), top = Math.max(...zs), low = Math.min(...zs);
|
|
277
|
+
return bed === 'top' ? transform([1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, top, 1], fit) : translate([0, 0, -low], fit);
|
|
278
|
+
}
|
|
279
|
+
const lengthOk = (what, L) => { if (!(isNum(L) && L > 0 && L <= 2000)) throw new Error(`${what}: length is the strip's, in mm, above 0 and up to 2000 (got ${shown(L)})`); return L; };
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* A printed cover that closes a slot nothing uses: a thin flange on the face, a stem in the slot's opening and a barb
|
|
283
|
+
* under each lip, leaning 45° so it prints. It prints lying down, its flange on the bed.
|
|
284
|
+
* @param {string | object} profile @param {{ length: number, face?: string, printer?: object, material?: string | object, given?: object }} o
|
|
285
|
+
* @returns {object} its model
|
|
286
|
+
*/
|
|
287
|
+
export function slotCoverModel(profile, o = {}) {
|
|
288
|
+
const what = 'slotCoverModel';
|
|
289
|
+
options(what, o ?? {}, ['length', 'face', 'printer', 'material', 'given']);
|
|
290
|
+
const L = lengthOk(what, o.length), given = o.given ?? {}, p = profileOf(what, profile, given), k = partSetup(what, o);
|
|
291
|
+
const sd = slotSide(what, p, o.face ?? 'top', undefined, null, k.fit, given);
|
|
292
|
+
const op = sd.slot.opening, lip = sd.slot.lip, ws = r3(op - 2 * k.fit), b = PANEL_DEFAULTS.barb.value, tf = r3(up(2 * k.layer + k.layer, k.layer)), lap = PANEL_DEFAULTS.lap.value, half = r3(op / 2 + lap);
|
|
293
|
+
if (ws < 2 * k.line) throw new Error(`${what}: ${sd.slot.name}'s ${mm(op)} mm opening leaves a stem ${mm(ws)} mm wide: too thin to print`);
|
|
294
|
+
const loop = [[-half, 0], [-ws / 2, 0], [-ws / 2, -lip], [-ws / 2 - b, -lip - b], [-ws / 2, -lip - 2 * b], [-ws / 2 + b, -lip - 2 * b - b], [ws / 2 - b, -lip - 3 * b], [ws / 2, -lip - 2 * b], [ws / 2 + b, -lip - b], [ws / 2, -lip], [ws / 2, 0], [half, 0], [half, tf], [-half, tf]].map(([y, z]) => [r3(y), r3(z)]);
|
|
295
|
+
const m = { kind: 'fitting', fitting: 'slot-cover', name: `slot-cover-${sd.slot.name.replace(/^slot-/, '')}-${Math.round(L)}`, title: `printed slot cover for ${sd.slot.name}, ${mm(L)} mm`, profile: p.name, face: sd.face, slot: sd.slot.name, length: L, section: loop,
|
|
296
|
+
flange: tf, stem: ws, barb: b, screws: [], load: { force: 0, what: 'none: it carries nothing' }, stress: 0, margin: Infinity, size: { length: L, flange: tf, stem: ws, barb: b }, volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [],
|
|
297
|
+
rests: ['barb', 'lap'].map((x) => ({ name: `PANEL_DEFAULTS.${x}`, value: PANEL_DEFAULTS[x].value, kind: PANEL_DEFAULTS[x].kind })) };
|
|
298
|
+
weigh(m, slotCover(m), k.density);
|
|
299
|
+
m.findings.push(finding('info', `${m.title}: a ${mm(tf)} mm flange lapping the face ${mm(lap)} mm past the opening, a ${mm(ws)} mm stem through the ${mm(lip)} mm lip, barbs ${mm(b)} mm past the opening under it (an estimate: try one in a scrap of beam)`, 'fitting.size', { values: { ...m.size } }));
|
|
300
|
+
m.findings.push(finding('info', 'it is drawn to print lying down, its flange on the bed, the barbs\' faces leaning 45°: no supports (printcheck\'s check() reads the solid)', 'fitting.printable', { values: { pose: 'flange down' } }));
|
|
301
|
+
m.findings.push(finding('info', `it weighs ${mm(m.grams)} g of ${m.material} (${mm(m.volume)} mm³)`, 'fitting.mass', { values: { grams: m.grams, volume: m.volume } }));
|
|
302
|
+
return m;
|
|
303
|
+
}
|
|
304
|
+
/** A slot cover's solid: flange down to print (pose 'print'), or fitted (pose 'fit'). @param {object} m @param {{ pose?: 'print' | 'fit' }} [o] @returns {object} */
|
|
305
|
+
export function slotCover(m, o = {}) {
|
|
306
|
+
if (m?.fitting !== 'slot-cover') throw new Error(`slotCover: give a slot cover's model (slotCoverModel), not ${shown(m)}`);
|
|
307
|
+
return Object.assign(stripSolid(m.section, m.length, 'top', o.pose), { model: m });
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* A printed edge that holds a sheet thinner than a slot's opening in the slot: a channel as wide as the opening less
|
|
312
|
+
* the fit, a groove as wide as the sheet with the fit, as deep as the lip and the cavity allow. Refused by name where
|
|
313
|
+
* the sheet leaves walls thinner than the printer's lines allow. It prints lying down, its groove up.
|
|
314
|
+
* @param {string | object} profile @param {{ sheet: number, length: number, face?: string, printer?: object, material?: string | object, given?: object }} o
|
|
315
|
+
* @returns {object} its model: depth (how far the sheet goes into the slot past the face)
|
|
316
|
+
*/
|
|
317
|
+
export function panelEdgeModel(profile, o = {}) {
|
|
318
|
+
const what = 'panelEdgeModel';
|
|
319
|
+
options(what, o ?? {}, ['sheet', 'length', 'face', 'printer', 'material', 'given']);
|
|
320
|
+
const T = sheetThickness(what, o.sheet), L = lengthOk(what, o.length), given = o.given ?? {}, p = profileOf(what, profile, given), k = partSetup(what, o);
|
|
321
|
+
const sd = slotSide(what, p, o.face ?? 'top', undefined, null, k.fit, given), op = sd.slot.opening, ws = r3(op - 2 * k.fit), groove = r3(T + 2 * k.fit), wall = r3((ws - groove) / 2), least = 2 * k.line;
|
|
322
|
+
if (wall < least - 1e-9) throw new Error(`${what}: a ${mm(T)} mm sheet in ${sd.slot.name}'s ${mm(op)} mm opening leaves walls of ${mm(wall)} mm, under the ${mm(least)} mm two of ${k.pr.name}'s lines make: a sheet of ${mm(Math.max(0, ws - 2 * least - 2 * k.fit))} mm or less, or panel clips on the face`);
|
|
323
|
+
const floor = r3(up(2 * k.layer, k.layer)), depth = r3(Math.min(sd.slot.cavityDepth - FITTING_DEFAULTS.floor.value, sd.slot.lip + 2)), h = depth;
|
|
324
|
+
const loop = [[-ws / 2, -h], [ws / 2, -h], [ws / 2, 0], [groove / 2, 0], [groove / 2, -h + floor], [-groove / 2, -h + floor], [-groove / 2, 0], [-ws / 2, 0]].map(([y, z]) => [r3(y), r3(z)]);
|
|
325
|
+
const m = { kind: 'fitting', fitting: 'panel-edge', name: `panel-edge-${sd.slot.name.replace(/^slot-/, '')}-${mm(T)}mm-${Math.round(L)}`, title: `printed in-slot edge for a ${mm(T)} mm sheet in ${sd.slot.name}, ${mm(L)} mm`, profile: p.name, face: sd.face, slot: sd.slot.name,
|
|
326
|
+
sheet: T, length: L, section: loop, width: ws, groove, wall, depth: r3(h - floor), screws: [], load: { force: 0, what: 'the sheet\'s own weight' }, stress: 0, margin: Infinity, size: { width: ws, groove, wall, depth: r3(h - floor), length: L },
|
|
327
|
+
volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [], rests: [{ name: `${k.pr.name}.fit`, value: k.fit }] };
|
|
328
|
+
weigh(m, panelEdge(m), k.density);
|
|
329
|
+
m.findings.push(finding('info', `${m.title}: ${mm(ws)} mm wide in the ${mm(op)} mm opening, its groove ${mm(groove)} mm (the sheet and the fit each side), walls ${mm(wall)} mm; the sheet goes ${mm(h - floor)} mm into the slot past the face`, 'fitting.size', { values: { ...m.size } }));
|
|
330
|
+
m.findings.push(finding('info', 'it is drawn to print lying down, its floor on the bed and its groove up: no supports', 'fitting.printable', { values: { pose: 'floor down' } }));
|
|
331
|
+
m.findings.push(finding('info', `it weighs ${mm(m.grams)} g of ${m.material} (${mm(m.volume)} mm³)`, 'fitting.mass', { values: { grams: m.grams, volume: m.volume } }));
|
|
332
|
+
return m;
|
|
333
|
+
}
|
|
334
|
+
/** An in-slot panel edge's solid: floor down to print, or fitted. @param {object} m @param {{ pose?: 'print' | 'fit' }} [o] @returns {object} */
|
|
335
|
+
export function panelEdge(m, o = {}) {
|
|
336
|
+
if (m?.fitting !== 'panel-edge') throw new Error(`panelEdge: give a panel edge's model (panelEdgeModel), not ${shown(m)}`);
|
|
337
|
+
return Object.assign(stripSolid(m.section, m.length, 'bottom', o.pose), { model: m });
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* A printed gasket strip for a door's gap: a hollow triangle of thin walls, its base taped to the door's inner face,
|
|
342
|
+
* as high as the gap and the squeeze, so the closing door presses it onto the beam's face. Its walls lean 30° from
|
|
343
|
+
* upright, so it prints lying on its base and folds rather than buckles. Best in PETG, which springs back where PLA creeps.
|
|
344
|
+
* @param {{ gap: number, length: number, squeeze?: number, printer?: object, material?: string | object }} o
|
|
345
|
+
* @returns {object} its model: strain (its walls' at the squeeze) against the plastic's limit
|
|
346
|
+
*/
|
|
347
|
+
export function gasketStripModel(o = {}) {
|
|
348
|
+
const what = 'gasketStripModel';
|
|
349
|
+
options(what, o ?? {}, ['gap', 'length', 'squeeze', 'printer', 'material']);
|
|
350
|
+
if (!(isNum(o.gap) && o.gap > 0)) throw new Error(`${what}: gap is the door's standoff from the beam's face, in mm, above 0 (got ${shown(o.gap)})`);
|
|
351
|
+
const L = lengthOk(what, o.length), k = partSetup(what, { material: 'petg', ...o }), sq = o.squeeze ?? PANEL_DEFAULTS.squeeze.value;
|
|
352
|
+
if (!(isNum(sq) && sq > 0 && sq < o.gap)) throw new Error(`${what}: squeeze is how far the door presses it, in mm, above 0 and under the gap (got ${shown(o.squeeze)})`);
|
|
353
|
+
const h = r3(o.gap + sq), t = r3(2 * k.line), half = r3(h * Math.tan(Math.PI / 6)), E = k.mat.rules.modulus.value;
|
|
354
|
+
const outer = [[-half, 0], [half, 0], [0, h]], d = t / Math.cos(Math.PI / 6), inner = [[-half + d * 1.8, t], [half - d * 1.8, t], [0, h - 2 * d]];
|
|
355
|
+
// each wall a cantilever of its slant length, pushed sq at its tip: strain 3 t δ / (2 L²)
|
|
356
|
+
const slant = Math.hypot(half, h), strain = r3((3 * t * sq) / (2 * slant * slant)), limit = r3(k.S / E), margin = r3(limit / strain);
|
|
357
|
+
const m = { kind: 'fitting', fitting: 'gasket-strip', name: `gasket-strip-${mm(o.gap)}mm-${Math.round(L)}`, title: `printed gasket strip for a ${mm(o.gap)} mm gap, ${mm(L)} mm`, length: L, height: h, wall: t, base: r3(2 * half), squeeze: sq, outer, inner,
|
|
358
|
+
screws: [], load: { force: 0, what: `the door pressing it ${mm(sq)} mm` }, strain, stress: r3(strain * E), margin, size: { height: h, base: r3(2 * half), wall: t, length: L }, volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [],
|
|
359
|
+
rests: [{ name: `${k.mat.name}.strength`, value: k.S }, { name: `${k.mat.name}.modulus`, value: E }, { name: 'PANEL_DEFAULTS.squeeze', value: sq, kind: PANEL_DEFAULTS.squeeze.kind }] };
|
|
360
|
+
weigh(m, gasketStrip(m), k.density);
|
|
361
|
+
const ok = margin >= want() - 1e-9;
|
|
362
|
+
m.findings.push(finding('info', `${m.title}: a hollow triangle ${mm(h)} mm high on a ${mm(2 * half)} mm base, walls ${mm(t)} mm (two lines), squeezed ${mm(sq)} mm`, 'fitting.size', { values: { ...m.size } }));
|
|
363
|
+
m.findings.push(finding(ok ? 'pass' : 'warn', `pressed ${mm(sq)} mm, its walls bend to a strain of ${mm(strain * 100)}%, ${mm(margin)} times under ${m.material.toUpperCase()}'s ${mm(limit * 100)}% (its strength over its modulus): by beam formulas, an estimate${m.material === 'pla' ? '. PLA creeps held bent: PETG keeps its spring' : ''}`, 'fitting.margin', { values: { strain, limit, margin } }));
|
|
364
|
+
m.findings.push(finding('info', 'it is drawn to print lying on its base, its walls leaning 30° from upright: no supports', 'fitting.printable', { values: { pose: 'base down' } }));
|
|
365
|
+
m.findings.push(finding('info', `it weighs ${mm(m.grams)} g of ${m.material} (${mm(m.volume)} mm³)`, 'fitting.mass', { values: { grams: m.grams, volume: m.volume } }));
|
|
366
|
+
return m;
|
|
367
|
+
}
|
|
368
|
+
/** A gasket strip's solid, base down (its print pose and, turned over onto the door, its fitted one). @param {object} m @returns {object} */
|
|
369
|
+
export function gasketStrip(m) {
|
|
370
|
+
if (m?.fitting !== 'gasket-strip') throw new Error(`gasketStrip: give a gasket strip's model (gasketStripModel), not ${shown(m)}`);
|
|
371
|
+
const turn = (dy) => [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, dy, 0, 1]; // (u, v) to (X, Z), along -Y
|
|
372
|
+
const body = transform(turn(m.length), prism(m.outer, m.length)), hollow = transform(turn(m.length + 1), prism(m.inner, m.length + 2));
|
|
373
|
+
return Object.assign(subtract(body, hollow), { model: m });
|
|
374
|
+
}
|