Resources Numerical accuracy Calculation policy

Traced sketch into model edges

Turns the lines, arcs and circles traced from a photo of a hand sketch into straight edges on the ground.

How the precision is kept

Lines are copied as they come from the tracing engine. Arcs and circles become chains of straight segments, 48 to a full turn, so each segment spans at most 7.5°. The end points are computed in 64-bit; the chord approximation sets the accuracy of round shapes.

Calculations under this policy

1 calculation 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.

sketch-photo-mc.js ModelCraft 0.8.1 64-bit 1 calculation Reviewed

Tests tools/modelcraft-test/sketch-photo.mjs

Arc and circle as straight segments

64-bit

The ground segments for one traced line, arc or circle.

aₖ = a₀ + sweep × k ÷ n; pₖ = [cx + r·cos aₖ, cy + r·sin aₖ, 0]

Each angle is computed from the start angle and the index, not by adding a step repeatedly. A point shared by two segments is computed by the same expression for both, so the two are identical. A sweep of zero or less has 2π added.

  • sketch-photo-mc.js
  • lines 27 to 38
  • ModelCraft 0.8.1
/** Ground segments [[x, y, 0], [x, y, 0]] for one traced entity (lines; arcs and circles as short straight runs). */
export function segmentsOf(e) {
  if (e.type === 'line') return [[[e.x1, e.y1, 0], [e.x2, e.y2, 0]]];
  const full = e.type === 'circle', a0 = full ? 0 : e.a0;
  let sweep = full ? Math.PI * 2 : e.a1 - e.a0;
  if (sweep <= 0) sweep += Math.PI * 2;
  const n = Math.max(2, Math.ceil(sweep / (Math.PI * 2 / ARC_SEGS)));
  const pt = (k) => { const a = a0 + (sweep * k) / n; return [e.cx + e.r * Math.cos(a), e.cy + e.r * Math.sin(a), 0]; };
  const out = [];
  for (let k = 0; k < n; k++) out.push([pt(k), pt(k + 1)]);
  return out;
}

In detail

Method
n = max(2, ⌈sweep ÷ (2π ÷ 48)⌉) equal chords along the arc.
Number types
64-bit numbers; meters on the ground.
Limits
A chord lies inside its arc by up to r × (1 − cos(π ÷ 48)), about 0.21% of the radius.

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