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

  • Numbers written into the macro

    A number as text in the macro.

    v.toPrecision(15)

    Sketch exchange macro and import swsketch.js
    • CadCraft
    64-bit
  • Millimeters per drawing unit

    The size of the drawing's unit in millimeters.

    inch 25.4; foot 304.8; yard 914.4; mil 0.0254; microinch 0.0000254

    Sketch exchange macro and import swsketch.js
    • CadCraft
    Exact
  • Arc ends on export

    The start and end points of an arc, which the macro needs beside its center.

    start = c + r(cos a₀, sin a₀); end = c + r(cos a₁, sin a₁)

    Sketch exchange macro and import swsketch.js
    • CadCraft
    64-bit
  • Center of a polyline arc segment

    The center of the arc between two polyline vertices with a bulge.

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

    Sketch exchange macro and import swsketch.js
    • CadCraft
    64-bit
  • Dimension values on export

    The value given to each dimension in the macro.

    angle: degrees × π ÷ 180; length: M(value)

    Sketch exchange macro and import swsketch.js
    • CadCraft
    64-bit
  • Arcs on import

    Builds an arc from the center, start and end points of an imported sketch.

    r = |start − center|; a₀ = atan2(start − center); a₁ = atan2(end − center), each in [0, 2π)

    Sketch exchange macro and import swsketch.js
    • CadCraft
    64-bit
  • Dimension values on import

    The value each imported dimension gets, and the parameter that drives it.

    parameter = round(value × 1e9) ÷ 1e9

    Sketch exchange macro and import swsketch.js
    • CadCraft
    64-bit
  • The line or circle under a pick

    Reads the picked object as an endless line with a unit direction, or as a full circle.

    direction = (p₂ − p₁) ÷ |p₂ − p₁|

    Circles tangent to two or three objects tancircle.js
    • CadCraft
    64-bit
  • Objects offset by the radius

    A line moved to both sides by r, and a circle grown and shrunk by r.

    line: p ± n·r; circle: R + r and |R − r|

    Circles tangent to two or three objects tancircle.js
    • CadCraft
    64-bit
  • Where two offset objects cross

    The crossing points of two lines, a line and a circle, or two circles.

    line–circle: t = −B ± √(B² − C), C = |f|² − r²; circles: l = (r₁² − r₂² + d²) ÷ 2d, h = √(r₁² − l²)

    Circles tangent to two or three objects tancircle.js
    • CadCraft
    64-bit
  • Is a circle tangent to an object

    Checks a candidate circle against a line or a circle.

    line: | |distance to line| − r | ≤ tol; circle: |d − (R + r)| ≤ tol or |d − |R − r|| ≤ tol

    Circles tangent to two or three objects tancircle.js
    • CadCraft
    64-bit
  • Tangent, tangent, radius

    The circle of radius r tangent to two picked objects, nearest the picks.

    center = crossing of a offset by r and b offset by r; tol = 1e-7 × max(1, size of a, b and r)

    Circles tangent to two or three objects tancircle.js
    • CadCraft
    64-bit
  • Newton solve for three tangents

    Solves the three tangency equations for a circle's center and radius from one starting guess.

    F(x, y, r) = 0; J by forward differences with h = 1e-7 × max(1, |x|, |y|, |r|); step = −J⁻¹F by Cramer's rule

    Circles tangent to two or three objects tancircle.js
    • CadCraft
    64-bit
  • Tangent, tangent, tangent

    The circle tangent to three picked objects, nearest the picks.

    8 sign choices × 18 starting guesses round the picks; kept when tangent to all three within 10 × tol

    Circles tangent to two or three objects tancircle.js
    • CadCraft
    64-bit
  • Touch point and choice by the picks

    Where a circle touches an object, and which candidate circle touches nearest the picked points.

    line: foot of the center on the line; circle: point of o on the line of centers

    Circles tangent to two or three objects tancircle.js
    • CadCraft
    64-bit
  • Height unit factor

    The factor that turns a file's heights into the project's unit.

    factor = meters per file unit ÷ meters per project unit

    Elevation grids into survey points and a grid surface terrain.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Cell center in the file's coordinates

    The x and y of a raster cell's center.

    x = g₀ + (col + 0.5)·g₁ + (row + 0.5)·g₂; y = g₃ + (col + 0.5)·g₄ + (row + 0.5)·g₅

    Elevation grids into survey points and a grid surface terrain.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Cells inside a box

    The range of columns and rows whose centers can fall inside a picked box.

    (col, row) = G⁻¹·(x − g₀, y − g₃) − 0.5; c₀ = ⌈min − 1e-9⌉, c₁ = ⌊max + 1e-9⌋ + 1

    Elevation grids into survey points and a grid surface terrain.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • A box through a coordinate conversion

    The box round a rectangle after its outline is converted to another coordinate system.

    17 points along each side, converted, then minimum and maximum

    Elevation grids into survey points and a grid surface terrain.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Survey points from a grid

    One survey point per grid node that has a height.

    (x, y) = conversion(cell center); z = file height × unit factor

    Elevation grids into survey points and a grid surface terrain.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Grid surface

    A triangulated surface from the grid: two triangles per cell.

    cell corners a (SW), b (SE), c (NE), d (NW): triangles a–b–c and a–c–d

    Elevation grids into survey points and a grid surface terrain.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • 1-2-5 step

    Rounds a step up to 1, 2 or 5 times a power of ten.

    p = 10^⌊log₁₀ x⌋; m = x ÷ p; 1, 2, 5 or 10 × p

    Elevation grids into survey points and a grid surface terrain.js
    • CadCraft
    • BimCraft
    • CivilCraft
    64-bit
  • Ray angles

    The directions offered at every multiple of the angle step.

    aᵢ = start + i × step × (π ÷ 180), i = 0 … round(360 ÷ step) − 1

    Polar and object snap tracking tracking.js
    • CadCraft
    64-bit
  • Pointer projected onto a ray

    The point of a ray nearest the pointer, and how far the pointer is from it.

    t = (q − p)·u; point = p + u·t, u = (cos a, sin a)

    Polar and object snap tracking tracking.js
    • CadCraft
    64-bit
  • Crossing of two tracking rays

    The point where rays from two acquired points cross.

    den = a × b; t = ((B − A) × b) ÷ den; point = A + a·t

    Polar and object snap tracking tracking.js
    • CadCraft
    64-bit
  • User coordinates to world

    A point or direction typed in the user coordinate system, in world coordinates.

    x = u.x + pₓ·cos − p_y·sin; y = u.y + pₓ·sin + p_y·cos

    User coordinate systems ucs.js
    • CadCraft
    64-bit
  • World coordinates to user

    A world point in the user coordinate system, as shown in coordinates and prompts.

    d = p − origin; x = dₓ·cos + d_y·sin; y = −dₓ·sin + d_y·cos

    User coordinate systems ucs.js
    • CadCraft
    64-bit
  • Is a coordinate system the world

    Normalizes a coordinate system and stores it as the world when it is the same.

    world when |x| < 1e-12, |y| < 1e-12 and angle within 1e-12 of 0 or 2π

    User coordinate systems ucs.js
    • CadCraft
    64-bit
  • Coordinate system from an origin and an X-axis point

    The coordinate system whose X axis runs from one picked point through another.

    angle = atan2(p_y − o_y, pₓ − oₓ)

    User coordinate systems ucs.js
    • CadCraft
    64-bit
  • Coordinate system from a polyline segment

    The coordinate system at the start of the polyline segment picked, with X along it.

    angle = atan2 of (point at 0.001 of the segment − its start)

    User coordinate systems ucs.js
    • CadCraft
    64-bit
  • Pointer position to drawing coordinates

    The drawing point under a screen position, in the active pane.

    u = (sx − w ÷ 2) ÷ zoom; v = (h ÷ 2 − sy) ÷ zoom; x = cx + cos(tw)·u − sin(tw)·v; y = cy + sin(tw)·u + cos(tw)·v

    Picked points, object snaps and viewport views view.js
    • CadCraft
    64-bit
  • Object snap under the pointer

    The best snap point (endpoint, midpoint, center, intersection and so on) within the aperture of the pointer.

    r = px ÷ zoom; keep candidates with |c − p| ≤ r; lowest priority number wins, then the smallest distance

    Picked points, object snaps and viewport views view.js
    • CadCraft
    64-bit
  • Viewport view after pan or zoom inside it

    The center, scale and twist an entered sheet viewport shows on screen, returned for the caller to store in the viewport when they differ from the stored ones.

    M = P⁻¹ · T; s = √(M₀² + M₁²); tw = atan2(M₁, M₀); center = M⁻¹ · (vp.x, vp.y)

    Picked points, object snaps and viewport views view.js
    • CadCraft
    64-bit
  • View to matrix

    The drawing-to-pixel matrix of a view for a pane of a given size.

    [z·c, z·s, z·s, −z·c, w ÷ 2 − z·(c·cx + s·cy), h ÷ 2 + z·(−s·cx + c·cy)] with c = cos(tw), s = sin(tw), z = zoom

    Picked points, object snaps and viewport views view.js
    • CadCraft
    64-bit
  • Matrix to view

    Reads the center, zoom and turn back out of a drawing-to-pixel matrix.

    zoom = √(A₀² + A₁²); tw = atan2(A₁, A₀); center = A⁻¹ · (w ÷ 2, h ÷ 2)

    Picked points, object snaps and viewport views view.js
    • CadCraft
    64-bit
  • Inverse of a 2 × 3 matrix

    The inverse of a drawing-to-pixel matrix.

    det = m₀·m₃ − m₁·m₂; inverse = adjugate ÷ det

    Picked points, object snaps and viewport views view.js
    • CadCraft
    64-bit
  • Angle brought into one turn

    An angle reduced to the range −π to π.

    r = atan2(sin a, cos a); |r| < 1e-12 → 0

    Picked points, object snaps and viewport views view.js
    • CadCraft
    64-bit
  • Drawing coordinates to screen position

    Where a drawing point is on screen, in CSS pixels of the active pane.

    sx = (x − cx)·zoom + w ÷ 2; sy = h ÷ 2 − (y − cy)·zoom (with a turn: the difference is rotated first)

    2D drawing on screen view.js
    • CadCraft
    32-bit, display only
  • Origin of the cached paths

    The point the cached drawing paths are stored relative to.

    origin = middle of the extents of the visible objects; path point = point − origin

    2D drawing on screen view.js
    • CadCraft
    32-bit, display only
  • Grid spacing

    The spacing of the background grid: 1, 2 or 5 times a power of ten, at least 14 pixels apart.

    target = 14 ÷ zoom; p = 10^⌊log₁₀ target⌋; step = first of p, 2p, 5p, 10p that is ≥ target; major = 5 × step

    2D drawing on screen view.js
    • CadCraft
    32-bit, display only
  • Pixels per paper millimeter

    How many CSS pixels one millimeter of the sheet takes, used to draw lineweights at their paper width.

    √(T₀² + T₁²) ÷ (25.4 when the paper is in inches, else 1)

    2D drawing on screen view.js
    • CadCraft
    32-bit, display only
  • Band of a wide polyline segment

    The filled outline of one polyline segment that has a start and end width.

    h(t) = (w₀ + (w₁ − w₀)·t) ÷ 2; left = p + n·h; right = p − n·h; arc: k = max(2, ⌈sweep ÷ 10°⌉) steps

    Wide polylines, text masks and ellipses as drawn and plotted walk.js
    • CadCraft
    64-bit
  • Corner between two wide segments

    The wedge that fills the outside gap where one wide segment meets the next.

    cross = tₐ × t_b; s = ((P₂ − P₁) × t_b) ÷ cross; X = P₁ + s·tₐ; used when s ≥ 0 and |X − corner| ≤ 10 × max(hₐ, h_b)

    Wide polylines, text masks and ellipses as drawn and plotted walk.js
    • CadCraft
    64-bit
  • Text background mask

    The rectangle painted behind a text: its box grown by a margin and turned with the text.

    m = max(0, scale − 1) × height; corner = (x, y) + R(rot) · (x₀ − m, y₀ − m) …

    Wide polylines, text masks and ellipses as drawn and plotted walk.js
    • CadCraft
    64-bit
  • Ring direction

    Turns a ring clockwise so that overlapping rings add up when filled.

    a = Σ (xᵢ·yᵢ₊₁ − xᵢ₊₁·yᵢ); a > 0 → reverse the points

    Wide polylines, text masks and ellipses as drawn and plotted walk.js
    • CadCraft
    64-bit
  • Ellipse as line pieces

    The line pieces an ellipse is drawn and plotted with.

    Wide polylines, text masks and ellipses as drawn and plotted walk.js
    • CadCraft
    64-bit
  • Linetype scale of an object

    The factor that sizes the dashes of an object's linetype.

    scale = LTSCALE × object scale × plot style table scale (non-ISO linetypes only)

    Wide polylines, text masks and ellipses as drawn and plotted walk.js
    • CadCraft
    64-bit
  • Point in polygon

    Whether a point lies inside the clip polygon.

    count edges with (aᵧ > pᵧ) ≠ (bᵧ > pᵧ) and pₓ < (bₓ − aₓ)·(pᵧ − aᵧ) ÷ (bᵧ − aᵧ) + aₓ; odd → inside

    Clipping block references to a boundary xclip.js
    • CadCraft
    64-bit
  • Where a line crosses the clip edges

    The positions along a line segment where it crosses the edges of the clip polygon.

    den = d × e; t = ((p − a) × e) ÷ den; u = ((p − a) × d) ÷ den; kept when EPS < t < 1 − EPS and −EPS ≤ u ≤ 1 + EPS

    Clipping block references to a boundary xclip.js
    • CadCraft
    64-bit
  • Line cut to the clip

    The pieces of a line that lie inside the clip polygon.

    piece ends = a + (b − a)·t₀ and a + (b − a)·t₁; kept when the middle point is inside

    Clipping block references to a boundary xclip.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.