Builds a parametric part for a standard bolt, nut, washer, pin, bearing or key at a size from the standards tables.
How the precision is kept
The sizes are table values from shapes/parts.js. Each value is rounded to 4 decimals of a millimeter before it becomes a parameter and a configuration row, which changes inch sizes that need more decimals. The sketches are then driven by those parameters through the sketch solver, so the geometry meets them within the solver's tolerance.
Open item. Keep the table values unrounded (or to at least 6 decimals) so that inch sizes convert exactly.
Calculations under this policy
4 calculations in 1 source file. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.
One row of parameter values (mm) per size of a standard part family.
value = Number(value.toFixed(4))
Each table value is rounded to 4 decimals of a millimeter before it is kept. Inch sizes in 32nds and 64ths need 5 or 6 decimals in millimeters (11/64 in = 4.365625 mm) and lose them here.
Draws a hexagon from its across-flats size and holds that size with a dimension.
e = s × 2 ÷ √3; first corner at (e ÷ 2, 0)
The corner circle's diameter is one 64-bit expression with Math.sqrt(3). The across-flats size itself is then added as a driving dimension between two opposite sides, so the solver, not this starting value, decides the final geometry.
stdparts.js
lines 43 to 51
PartCraft 0.8.1
/** A hexagon across flats `s` about the sketch origin, one flat along X; returns the across-flats dimension. */
function hexagon(sk, s) {
const e = s * 2 / Math.sqrt(3);
const poly = addPolygon(sk, [0, 0], [e / 2, 0], 6);
const circ = sk.entities.find((x) => x.id === poly.circle);
S.addConstraint(sk, 'coincident', [circ.c, S.ORIGIN]);
S.addConstraint(sk, 'horizontal', [poly.lines[1]]);
return S.addConstraint(sk, 'distance', [poly.lines[1], poly.lines[4]], s);
}
Circle of a given diameter
64-bit
Draws a circle about the origin and holds its diameter with a dimension.
r = d ÷ 2
The halving is exact; the diameter is stored as a driving dimension with the table value.
stdparts.js
lines 52 to 56
PartCraft 0.8.1
/** A circle Ø`d` about the origin; returns its diameter dimension. */
function round(sk, d) {
const c = S.addCircle(sk, S.ORIGIN, d / 2);
return S.addConstraint(sk, 'diameter', [c.id], d);
}
Parallel key outline
64-bit
The round-ended outline of a parallel key from its width and length.
half = (l − b) ÷ 2; center distance = l − b; end radius = b ÷ 2
One subtraction and exact halvings in 64-bit. The center distance and end radius are also linked to the parameters as the expressions l − b and b / 2.
stdparts.js
lines 123 to 132
PartCraft 0.8.1
const half = (v.l - v.b) / 2;
const slot = addSlot(s, [-half, 0], [half, 0], v.b);
const [ca, cb] = slot.centres;
S.addConstraint(s, 'horizontal', [ca, cb]);
// symmetric about a fixed construction line up the Y axis through the origin
const ax = S.addLine(s, S.ORIGIN, [0, 1], { construction: true });
S.addConstraint(s, 'vertical', [ax.id]);
S.addConstraint(s, 'fix', [ax.p2]);
S.addConstraint(s, 'symmetric', [ca, cb, ax.id]);
return { len: S.addConstraint(s, 'distance', [ca, cb], v.l - v.b), r: S.addConstraint(s, 'radius', [slot.arcs[0]], v.b / 2) };
In detail
Method
Table lookup per size; hexagon from its across-flats size by the circumscribed circle e = 2s ÷ √3; dimensions linked to parameters.
Number types
64-bit numbers; parameter values written as text with at most 4 decimals.
Limits
Inch sizes in 64ths do not fit 4 decimals of a millimeter: 11/64 in = 4.365625 mm is stored as 4.3656. Threads and end chamfers are not modeled. The material density 7.85 g/cm³ is a nominal value for steel.
Approach: 64-bit, stated limit
The arithmetic is 64-bit, but the method or the data sets the accuracy: a solver tolerance, a mesh, a step size, a datum shift, a table. The limit is stated where the result is shown.