Resources Numerical accuracy

Calculations

Every calculation under our calculation policies: what it works out, its formula and the precision it runs at. Open one to see its code as it is in the released app.

  • 6,917 calculations in 1,248 source files
  • 143 exact
  • 6,286 in 64-bit
  • 335 with a 32-bit step
  • Last reviewed

Calculations

  • Traced arcs and circles

    Turns each traced arc into a circle or an arc object in drawing units.

    r = r(px) × units per px; arc through start, middle and end

    Sketch photo to drawing photosketch.js
    • CadCraft
    64-bit
  • Layout sheet in millimeters

    The matrix that takes a layout and its viewports to millimeters on the sheet.

    toMm = [k 0 0 k −x₀k −y₀k], k = mm per paper unit; view matrix = toMm · viewport matrix

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Model plot scale and placement

    The scale and offset that put a window of the model on a paper size, fitted or at 1:n.

    fit: s = min((W − 10) ÷ w, (H − 10) ÷ h); offset = (W ÷ 2 − cₓs, H ÷ 2 − c_y·s)

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Millimeters to points in the page

    The factor that lets the rest of the PDF page be written in millimeters.

    72 ÷ 25.4 = 2.834645669 (9 decimals)

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Numbers written to the PDF and SVG

    Turns a coordinate, width or size into the text that goes into the file.

    text = v.toFixed(4), trailing zeros dropped; |v| < 0.00005 → 0

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Arcs as cubic Béziers

    The Bézier pieces that draw an arc in the PDF.

    n = ⌈|sweep| ÷ 90°⌉; d = sweep ÷ n; k = 4⁄3 · tan(d ÷ 4); handles at r·k along the tangents

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Lines and arcs in the page

    Writes each line and arc of a stroke group as PDF path operators.

    arc start = c + r(cos a, sin a)

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Text placement in the PDF

    The text matrix of each line of text: size, width factor, rotation, lean and position.

    size = h × FONT_EM; width = advance ÷ 1000 × size × wf; lean = size × tan(oblique)

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Page size in points

    The PDF page's width and height from the sheet's millimeters.

    pt = mm × 72 ÷ 25.4, written with 4 decimals

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Lines and arcs in the SVG

    Writes each line and arc of a stroke group as SVG path data.

    arc pieces of at most 90°: A r r 0 0 flag x y

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Paper size from a printer's paper name

    The size in millimeters of a named paper such as A3, Letter or 24 x 36 in.

    A-series: start 841 × 1189, each step (w, h) → (⌊h ÷ 2⌋, w); inches × 25.4

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Matching a sheet to a printer paper

    Finds the printer paper that is the sheet's size.

    |short − a| ≤ 2 mm and |long − b| ≤ 2 mm

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • PNG size in pixels

    The pixel width and height of a sheet at a resolution, held under what a canvas can make.

    px = round(mm ÷ 25.4 × dpi), at least 1; while too big: dpi = ⌊dpi × 0.9⌋

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Plot extents of the model

    The box round everything the model would plot.

    Plotting: sheet scale, PDF, SVG and PNG output plot.js
    • CadCraft
    64-bit
  • Lengths with units inside an entry

    Replaces 900mm, 2ft or 3'6" in the typed text by the same length in drawing units.

    mm = feet × 304.8 + inches × 25.4, or value × mm per unit; text = (mm ÷ mm per drawing unit) to 12 significant digits

    Values typed in the Properties panel propexpr.js
    • CadCraft
    64-bit
  • Degrees, minutes and seconds inside an expression

    Replaces 45°30'15" in an angle expression by decimal degrees.

    degrees + minutes ÷ 60 + seconds ÷ 3600, written with 12 significant digits

    Values typed in the Properties panel propexpr.js
    • CadCraft
    64-bit
  • Full-precision text of a value

    The text a number field shows while it is edited.

    v.toPrecision(12)

    Values typed in the Properties panel propexpr.js
    • CadCraft
    64-bit
  • Millimeters per drawing unit

    The size of one drawing unit, or of the sheet's paper unit, in millimeters.

    inch 25.4; foot 304.8; yard 914.4; mile 1 609 344

    Values typed in the Properties panel propexpr.js
    • CadCraft
    Exact
  • Limits on a typed value

    Checks a result against the field's kind and limits.

    whole number: |v − round(v)| ≤ 1e-9; v ≥ min − 1e-12; v ≤ max + 1e-12

    Values typed in the Properties panel propexpr.js
    • CadCraft
    64-bit
  • Angles typed in radians, grads or degrees-minutes-seconds

    Reads 0.5r, 100g or 45°30'15" as degrees.

    radians × (180 ÷ π); grads × 0.9; d + m ÷ 60 + s ÷ 3600

    Values typed in the Properties panel propexpr.js
    • CadCraft
    64-bit
  • Pixels to drawing coordinates and back

    Maps a pixel of a placed picture to the drawing, a drawing point back to a pixel, and gives the size of one pixel.

    block = p + u·px + v·(h − py); drawing = M·block; pixel size = |M·u|

    Scanned drawings: size, scale, align, crop and trace scan.js
    • CadCraft
    64-bit
  • Arc through three points

    The counterclockwise arc through a start, a middle and an end point.

    d = 2(aₓ(b_y − c_y) + bₓ(c_y − a_y) + cₓ(a_y − b_y)); center from |a|², |b|², |c|² ÷ d; r = |a − center|

    Scanned drawings: size, scale, align, crop and trace scan.js
    • CadCraft
    64-bit
  • Traced lines and arcs as drawing objects

    Turns a trace result in pixels into lines, arcs and circles in drawing coordinates.

    circle r = r(px) × pixel size; arc through start, middle and end

    Scanned drawings: size, scale, align, crop and trace scan.js
    • CadCraft
    64-bit
  • First size of an attached scan

    The size of one pixel when a scan is attached.

    per pixel = 25.4 ÷ dpi when the file states it and the drawing has units, else 1; typed width ÷ pixel width

    Scanned drawings: size, scale, align, crop and trace scan-cmd.js
    • CadCraft
    64-bit
  • Scale from two points and a real distance

    Rescales a scan so two picked points are a stated distance apart.

    f = wanted ÷ |b − a|; insertion′ = a + f·(insertion − a); sx′ = sx·f

    Scanned drawings: size, scale, align, crop and trace scan-cmd.js
    • CadCraft
    64-bit
  • Align by two pairs of points

    Moves, turns and optionally scales a scan so two points on it land on two points of the drawing.

    f = |d₂ − d₁| ÷ |s₂ − s₁|; θ = atan2(d₂ − d₁) − atan2(s₂ − s₁); insertion′ = d₁ + f·R(θ)·(insertion − s₁)

    Scanned drawings: size, scale, align, crop and trace scan-cmd.js
    • CadCraft
    64-bit
  • Straightening a skewed scan

    Turns the picture back by the skew angle that was found or typed.

    Scanned drawings: size, scale, align, crop and trace scan-cmd.js
    • CadCraft
    64-bit
  • Crop window in pixels

    The whole-pixel window of a crop and the new corner of the cropped picture.

    x₀ = ⌊min⌋, y₀ = ⌊min⌋, x₁ = ⌈max⌉, y₁ = ⌈max⌉; corner = p + u·x₀ + v·(h − y₁)

    Scanned drawings: size, scale, align, crop and trace scan-cmd.js
    • CadCraft
    64-bit
  • Trace tolerance

    The tolerance of a trace, typed in drawing units and used in pixels.

    tolerance (px) = typed ÷ pixel size, held to 0.5 … 20

    Scanned drawings: size, scale, align, crop and trace scan-cmd.js
    • CadCraft
    64-bit
  • Outline moved inward

    The outline offset inward by a distance, with mitered corners.

    corner′ = corner + bisector × d ÷ cos(half angle)

    Tapered, revolved and swept solids shapes3d.js
    • CadCraft
    64-bit
  • Signed volume and face direction

    Works out whether the faces point outward and refuses a solid with no volume.

    V = Σ p₀ · (pᵢ × pᵢ₊₁) ÷ 6 over fan triangles

    Tapered, revolved and swept solids shapes3d.js
    • CadCraft
    64-bit
  • Tapered extrusion

    A solid whose top is the outline inset by the height times the tangent of the taper angle.

    inset = |h| × tan(angle); vertices relative to the outline's minimum x and y

    Tapered, revolved and swept solids shapes3d.js
    • CadCraft
    64-bit
  • Revolution about an axis

    A solid made by turning the outline about an axis in steps.

    n = max(2, ⌈48 × |angle| ÷ 2π⌉); p′ = v·cos θ + (u × v)·sin θ + u(u·v)(1 − cos θ)

    Tapered, revolved and swept solids shapes3d.js
    • CadCraft
    64-bit
  • Sweep along a path

    A solid made by standing the outline across a path, with mitered corners.

    centroid = Σ (pᵢ + pⱼ)wᵢ ÷ 3Σwᵢ, wᵢ = xᵢyⱼ − xⱼyᵢ; frame normal = bisector ÷ cos(half angle)

    Tapered, revolved and swept solids shapes3d.js
    • CadCraft
    64-bit
  • Repeated path points

    Drops path points that repeat the one before.

    |pᵢ − pᵢ₋₁| ≤ 1e-9 → dropped

    Tapered, revolved and swept solids shapes3d.js
    • CadCraft
    64-bit
  • Pen moves

    Moves the pen by a displacement of the shape.

    x′ = x + dx × mul ÷ div

    SHX font text: strokes and width shx.js
    • CadCraft
    64-bit
  • Arcs as chords

    Draws an arc of a shape as short straight pieces.

    n = max(2, ⌈|sweep| ÷ 7.5°⌉); pointₖ = c + r(cos aₖ, sin aₖ), aₖ = a₀ + sweep × k ÷ n

    SHX font text: strokes and width shx.js
    • CadCraft
    64-bit
  • Bulge arcs

    An arc given by its chord and a bulge value.

    θ = 4·atan(b); r = chord ÷ (2·sin(|θ| ÷ 2)); center = chord middle ± r·cos(θ ÷ 2) across the chord

    SHX font text: strokes and width shx.js
    • CadCraft
    64-bit
  • Octant and fractional arcs

    Arcs given by a radius, a starting octant and a span of octants, with optional fractions of an octant.

    a₀ = (s₀ + so ÷ 256) × π ÷ 4; center = pen − r(cos a₀, sin a₀)

    SHX font text: strokes and width shx.js
    • CadCraft
    64-bit
  • Text strokes and width

    The strokes of a text for capitals of a given height, and the text's width.

    k = h ÷ capital height of the font; width = Σ glyph advance × k

    SHX font text: strokes and width shx.js
    • CadCraft
    64-bit
  • Width of a text in an SHX font

    The width the text layout uses for a text whose style names a loaded .shx font.

    width = advance × width factor

    SHX font text: strokes and width shx-text.js
    • CadCraft
    64-bit
  • Strokes placed in the drawing

    Each stroke point of a text taken to drawing coordinates with alignment, width factor, slant and rotation.

    lx = x₀ + (gx + gy·tan(oblique)) × wf; X = x + lx·cos − gy·sin; Y = y + lx·sin + gy·cos

    SHX font text: strokes and width shx-text.js
    • CadCraft
    64-bit
  • Circle through a stroke

    The circle that best fits the stroke's points, with its root-mean-square error.

    u = x − x̄, v = y − ȳ; solve [Σu² Σuv; Σuv Σv²]·(u_c, v_c) = ½(Σu³ + Σuv², Σv³ + Σvu²); r² = u_c² + v_c² + (Σu² + Σv²) ÷ n

    Pen sketch cleanup sketch.js
    • CadCraft
    • MarkupCraft
    64-bit
  • Turn of a stroke about a center

    How far the stroke goes round the fitted center, signed.

    Σ (aᵢ − aᵢ₋₁) with each step brought into (−π, π]

    Pen sketch cleanup sketch.js
    • CadCraft
    • MarkupCraft
    64-bit
  • Squaring a direction

    Makes a direction level or plumb when it is within a few degrees of it.

    q = round(a ÷ (π ÷ 2)) × (π ÷ 2); used when |a − q| ≤ deg × π ÷ 180

    Pen sketch cleanup sketch.js
    • CadCraft
    • MarkupCraft
    64-bit
  • Where two sides meet

    The corner where two straight sides cross.

    det = l × m; t = ((m₀ − l₀) × m) ÷ det; point = l₀ + l·t

    Pen sketch cleanup sketch.js
    • CadCraft
    • MarkupCraft
    64-bit
  • Distance from a point to a segment

    How far a pen point is from the straight line between two others.

    t = ((p − a)·(b − a)) ÷ |b − a|², held to [0, 1]; distance = |p − (a + t(b − a))|

    Pen sketch cleanup sketch.js
    • CadCraft
    • MarkupCraft
    64-bit
  • Straight sides and rectangles

    Cuts a stroke at its corners, squares each side, and rebuilds the corners where the sides cross.

    Pen sketch cleanup sketch.js
    • CadCraft
    • MarkupCraft
    64-bit
  • A stroke as a line

    Makes a nearly straight stroke a line, exactly level or plumb when it is close to it.

    straight when max distance ≤ max(eps, 3.5 % of the gap) and gap > 90 % of the length

    Pen sketch cleanup sketch.js
    • CadCraft
    • MarkupCraft
    64-bit
  • A stroke as a circle or an arc

    Makes a round stroke a circle, or an arc from the stroke's first point to its last.

    accepted when rms ÷ r < 0.07 and r < 3 × box diagonal; circle when |turn| > 0.85 × 2π

    Pen sketch cleanup sketch.js
    • CadCraft
    • MarkupCraft
    64-bit

A calculation is added only after its source was read. Each statement can be checked in the code shown on its policy's page; the app repositories are public. When a release changes a calculation, its page says so until it has been read again.