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

  • 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
  • Joining loose ends

    Pulls each loose end onto the nearest corner of another stroke or of the drawing.

    nearest corner with distance ≤ tol; tol = 6 % of the sketch's box diagonal unless given

    Pen sketch cleanup sketch.js
    • CadCraft
    • MarkupCraft
    64-bit
  • Point on a spline

    The curve's point at a parameter.

    de Boor: dⱼ = (1 − a)·dⱼ₋₁ + a·dⱼ, a = (u − kᵢ) ÷ (kᵢ₊ₚ₋ᵣ₊₁ − kᵢ); point = (Σ w·P) ÷ Σ w

    Splines: curve points, fitting and editing spline.js
    • CadCraft
    64-bit
  • Clamped knots

    The knot list for a spline that starts and ends on its first and last control points.

    p + 1 zeros, 1 … n − p − 1, p + 1 values of n − p

    Splines: curve points, fitting and editing spline.js
    • CadCraft
    Exact
  • Spline through fit points

    Builds the spline that passes through the points picked.

    two points: control points at 0, ⅓, ⅔ and 1 of the segment; more: clamped cubic with chord-length parameters

    Splines: curve points, fitting and editing spline.js
    • CadCraft
    64-bit
  • Spline from control points

    Builds a spline with a given control polygon, clamped or closed.

    closed: control points wrapped by the degree, knots 0, 1, 2, …

    Splines: curve points, fitting and editing spline.js
    • CadCraft
    64-bit
  • A spline as points

    The curve as a list of points for drawing and for anything that works from points.

    pieces per span = max(4·max(1, p − 1), ⌈√(polygon length ÷ tol)⌉), within a budget of 4000

    Splines: curve points, fitting and editing spline.js
    • CadCraft
    64-bit
  • A spline as a polyline

    Points for converting a spline to a polyline, a set number of segments per knot span.

    u = a + (b − a) × i ÷ n, n = 1 … 99 (10 unless given)

    Splines: curve points, fitting and editing spline.js
    • CadCraft
    64-bit
  • Adding a control point

    The same curve with one more control point at a parameter.

    Qᵢ = (1 − a)·Pᵢ₋₁ + a·Pᵢ, a = (u − kᵢ) ÷ (kᵢ₊ₚ − kᵢ), in weighted form

    Splines: curve points, fitting and editing spline.js
    • CadCraft
    64-bit
  • Reversing a spline

    The same curve run the other way.

    knot′ = (first + last) − knot, in reverse order

    Splines: curve points, fitting and editing spline.js
    • CadCraft
    64-bit
  • Control-point spline to fit points

    Samples points on a spline and builds a fit-point spline through them.

    n points evenly spaced in the parameter (12 unless given, at least 3)

    Splines: curve points, fitting and editing spline.js
    • CadCraft
    64-bit
  • Parameter nearest a picked point

    Where along the curve a new control point is added.

    nearest of 401 samples evenly spaced in the parameter

    Splines: curve points, fitting and editing spline-cmd.js
    • CadCraft
    64-bit
  • Arc as a polyline segment

    Turns an arc into a two-point polyline with a bulge.

    ends = c + r(cos a, sin a); bulge = tan((a₁ − a₀) ÷ 4)

    Splines: curve points, fitting and editing spline-cmd.js
    • CadCraft
    64-bit
  • Curve-fitted polyline

    A polyline redrawn as a smooth curve through or along its vertices, kept as many short segments.

    8 segments per knot span unless given

    Splines: curve points, fitting and editing spline-cmd.js
    • CadCraft
    64-bit
  • Mass per meter of a section

    The kilograms per meter shown for a steel section.

    kg/m = published mass, else area (mm²) × 1e-6 × 7850

    Standard sections: member solids, mass and parts list stdlib.js
    • CadCraft
    64-bit
  • Member solid

    The faces of a straight member along two points, or of a column of a given height.

    outline (mm) ÷ 1000; L = |b − a| × k; point = eₓ·u + e_y·(v + lift) + e_z·s

    Standard sections: member solids, mass and parts list stdlib.js
    • CadCraft
    64-bit
  • Parts list quantities

    Groups placed parts and adds up how many there are of each.

    qty = Σ CC-QTY (1 when absent)

    Standard sections: member solids, mass and parts list stdlib.js
    • CadCraft
    64-bit
  • Total mass in the parts list

    The mass column of the parts list and its CSV.

    mass = round(mass each × qty × 100) ÷ 100

    Standard sections: member solids, mass and parts list stdlib.js
    • CadCraft
    64-bit
  • A level written as text

    Reads a level such as 104.37, +104,37 or EL 104.37 from a text.

    value = Number(whole digits . decimal digits) × sign

    Survey levels from text and the survey check survey.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Levels into project units

    A level point's x, y and z in project units.

    x·k, y·k, z·k

    Survey levels from text and the survey check survey.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Extent and distance from the origin

    How far the data spans and how far it lies from zero, in meters.

    span = |(maxX − minX, maxY − minY)| × m per unit; far = max |coordinate| × m per unit

    Survey levels from text and the survey check survey.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Median

    The middle value of a list of levels.

    odd count: the middle value; even: mean of the two middle values

    Survey levels from text and the survey check survey.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Level outliers

    Counts levels that are far from the rest, and levels of exactly 0 that look like missing heights.

    MAD = median(|z − median|) × 1.4826; limit = max(6 × MAD, 5 m); outlier when |z − median| > limit

    Survey levels from text and the survey check survey.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Duplicate points

    Counts points that sit on top of another point, with the same or a different level.

    cell = 1 mm; key = (round(x ÷ cell), round(y ÷ cell)); same level when |Δz| ≤ cell

    Survey levels from text and the survey check survey.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Drawing units to meters

    A coordinate or length as the text the macro passes, in meters.

    m = round₁₂(round₉(v) × mm per unit ÷ 1000)

    Sketch exchange macro and import swsketch.js
    • CadCraft
    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.