Resources Numerical accuracy Calculation policy

Standard part templates

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.

stdparts.js PartCraft 0.8.1 64-bit 4 calculations Reviewed

Tests tools/partcraft-test/test-stdparts.mjs, bin/test-agents.mjs

Sizes of a template

64-bit

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.

  • stdparts.js
  • lines 58 to 70
  • PartCraft 0.8.1
/** One configuration row per size: { name, values } in the template's parameters (mm). */
function rows(id) {
  return partSizes(id).map((z) => {
    const p = makePart(id, z.size, partOptions(id, z.size)).part, x = p.dims;
    const values = {
      iso4017: { d: x.d, s: x.s, k: x.k, l: x.l }, iso4014: { d: x.d, s: x.s, k: x.k, l: x.l }, 'asme-hex-bolt': { d: x.d, s: x.s, k: x.k, l: x.l },
      iso4032: { d: x.d, s: x.s, height: x.m }, 'asme-hex-nut': { d: x.d, s: x.s, height: x.m }, iso7089: { d1: x.d1, d2: x.d2, h: x.h },
      iso2338: { d: x.d, l: x.l }, iso15: { d: x.d, D: x.D, B: x.B }, din6885: { b: x.b, h: x.h, l: x.l },
    }[id];
    for (const k of Object.keys(values)) values[k] = Number(values[k].toFixed(4));
    return { name: p.sizeText, size: z.size, values };
  });
}

Hexagon across flats

64-bit

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.

Every policy that takes this approach