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

  • Knot insertion

    Adds one knot to a spline without changing its shape.

    a = (u − Uᵢ) ÷ (Uᵢ₊ₚ − Uᵢ); Qᵢ = (1 − a)·Pᵢ₋₁ + a·Pᵢ

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    64-bit
  • Exact piece of a spline

    The part of a spline between two parameters as a curve of its own, used by trim.

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    64-bit
  • Knots rescaled to start at zero

    Shifts and scales a spline's knots so that they start at 0 and span the number of its pieces.

    u′ = (u − a) × (poles − degree) ÷ L

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    64-bit
  • Polyline within a chord tolerance

    Points along a spline such that every chord stays within a tolerance of the curve.

    split a piece while the curve at ¼, ½ or ¾ of it is farther than tol from its chord

    Sketch splines: length, nearest point, polyline and offset sketch-spline.js
    • PartCraft
    64-bit
  • Length of a spline

    The arc length of a spline.

    L = Σ over 8 pieces per span of Σ wᵢ × h × |C′(uᵢ)| (5-point Gauss–Legendre)

    Sketch splines: length, nearest point, polyline and offset sketch-spline.js
    • PartCraft
    64-bit
  • Nearest point on a spline

    The parameter of the point on a spline nearest a given point.

    start at the nearest of 13 samples per span; Newton: u ← u − ((C − p) · C′) ÷ (C′ · C′ + (C − p) · C″)

    Sketch splines: length, nearest point, polyline and offset sketch-spline.js
    • PartCraft
    64-bit
  • Offset of a spline

    A new fit spline that follows a spline at a fixed distance, with the largest gap found.

    true offset point = C(u) + d × n(u); err = max over 40 points per span of the distance to the fitted curve; accept when err ≤ tol

    Sketch splines: length, nearest point, polyline and offset sketch-spline.js
    • PartCraft
    64-bit
  • Sketch tolerance

    The base length tolerance of the sketch tools.

    tolOf = 1e-7 × max(1, extent of the sketch)

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Crossings of a curve with the others

    Where a curve is cut by every other curve of the sketch, for trim.

    crossings within tol of the curve's own ends, or of one already found, are left out; tol = 1e-4 × max(1, extent)

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Extending a line or arc

    Moves the picked end of a line or arc to the nearest curve it meets when continued.

    line: gap = (t − 1) × L or −t × L; arc: gap = (t − sweep) × r or (2π − t) × r; nearest gap > tol wins

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Offset of each curve

    The offset copy of each line, circle, arc or spline of a chain, before the corners are joined.

    line: S = a + d·n, E = b + d·n, n = (−Δy, Δx) ÷ L; circle: r − d; arc: r ∓ d, ends c + r·(cos, sin)

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Corners of an offset chain

    Joins neighboring offset curves at the point where they meet when extended.

    corner = the intersection of the two full lines or circles nearest the midpoint of the gap

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Mirror about a line

    Reflects points about a sketch line, and reflects a spline's end angles.

    t = (p − a) · u; q = a + t·u; p′ = 2q − p; angle′ = 2φ − angle

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Linear pattern

    Copies geometry a number of times along a step.

    copy i: (x + Δx × i, y + Δy × i)

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Circular pattern

    Copies geometry a number of times around a center.

    step = (360 ÷ count, or angle ÷ (count − 1)) × π ÷ 180; copy i: rotate about c by step × i

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Regular polygon

    The corners of a regular polygon from its center, one corner and the number of sides.

    cornerᵢ = c + r × (cos(a₀ + 2π·i ÷ n), sin(a₀ + 2π·i ÷ n))

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Straight slot

    The four corner points of a slot from its two centers and its width.

    r = w ÷ 2; corners = center ± n × r, n = unit normal of the center line

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Projecting a model edge

    Puts a straight or circular model edge onto the sketch plane as fixed geometry.

    (u, v) = ((p − o) · x, (p − o) · y)

    Sketch tools: trim, extend, offset, mirror, pattern, polygon, slot, project sketch-tools.js
    • PartCraft
    64-bit
  • Radius of a circle or arc

    The radius of a circle (stored) or of an arc (the distance from its center to its start point).

    r = |s − c|

    Sketch geometry and measured values sketch.js
    • PartCraft
    64-bit
  • Arc angles

    The center, radius, start angle and sweep of an arc from its three points.

    a₀ = atan2(s − c); sweep = atan2(e − c) − a₀, brought to (1e-12, 2π]

    Sketch geometry and measured values sketch.js
    • PartCraft
    64-bit
  • New arc: end point on the radius

    Places a new arc's end point on the circle through its start point.

    r = |s − c|; e = c + r × (cos a, sin a), a = atan2(e₀ − c)

    Sketch geometry and measured values sketch.js
    • PartCraft
    64-bit
  • Current value of a relation or dimension

    The value a new dimension starts with: a distance, a horizontal or vertical distance, a radius, a diameter, an offset or an angle, and which side it is on.

    distance = |b − a|; point to line = |signed distance|; diameter = 2r; angle° = |atan2(u × v, u · v)| × 180 ÷ π

    Sketch geometry and measured values sketch.js
    • PartCraft
    64-bit
  • Signed distance from a point to a line

    How far a point is from a line through two points, positive on the left.

    s = (Δx·(p_y − a_y) − Δy·(p_x − a_x)) ÷ |b − a|

    Sketch geometry and measured values sketch.js
    • PartCraft
    64-bit
  • Nearly parallel test

    Decides whether two lines are close enough to parallel to take a distance instead of an angle.

    |u × v| ÷ (|u| × |v|) < 1e-6

    Sketch geometry and measured values sketch.js
    • PartCraft
    64-bit
  • Sketch fillet

    Trims two lines at a corner and adds a tangent arc of a given radius between them.

    θ = acos(u₁ · u₂); d = r ÷ tan(θ ÷ 2); tangent points = P + uᵢ × d; center = P + bisector × r ÷ sin(θ ÷ 2)

    Sketch geometry and measured values sketch.js
    • PartCraft
    64-bit
  • Size of a sketch

    The largest coordinate size in a sketch, which the tolerances of the sketch code are scaled by.

    extent = max(|x|, |y| over the points; |c_x| + r, |c_y| + r over the circles)

    Sketch geometry and measured values sketch.js
    • PartCraft
    64-bit
  • Box of a sketch

    The bounding box of the sketch geometry.

    Sketch geometry and measured values sketch.js
    • PartCraft
    64-bit
  • Points along an arc

    An arc as a run of points from its start to its end.

    n = max(1, ⌈sweep ÷ 2π × segFull − 1e-9⌉); pointᵢ = c + r × (cos(a₀ + sweep·i ÷ n), sin(…))

    Sketch profiles as closed polygons sketch.js
    • PartCraft
    64-bit
  • Points around a circle

    A circle as a closed polygon with its corners on the circle.

    pointᵢ = c + r × (cos(2π·i ÷ n), sin(2π·i ÷ n))

    Sketch profiles as closed polygons sketch.js
    • PartCraft
    64-bit
  • Closed loops of a sketch

    Chains the sketch's curves into closed loops, or reports an open end or a branch.

    ends are one node when closer than 10 × tol, tol = 1e-6 × max(1, extent)

    Sketch profiles as closed polygons sketch.js
    • PartCraft
    64-bit
  • Point inside loops

    Tests whether a point lies inside a set of loops by the even-odd rule.

    count edges with (a_y > p_y) ≠ (b_y > p_y) and p_x < (b_x − a_x)·(p_y − a_y) ÷ (b_y − a_y) + a_x

    Sketch profiles as closed polygons sketch.js
    • PartCraft
    64-bit
  • Area of a loop

    The signed area of a polygon loop.

    area = ½ × Σ (xⱼ·yᵢ − xᵢ·yⱼ)

    Sketch profiles as closed polygons sketch.js
    • PartCraft
    64-bit
  • Jacobian by central differences

    The rate of change of every relation's residual with each variable it depends on.

    ∂f/∂x ≈ (f(x + h) − f(x − h)) ÷ 2h, h = 1e-6 × max(1, |x|)

    Sketch solver solver.js
    • PartCraft
    64-bit
  • Cholesky solve

    Solves the symmetric system of each Newton step.

    A = L·Lᵀ; L·y = b; Lᵀ·z = y

    Sketch solver solver.js
    • PartCraft
    64-bit
  • Damped Newton iteration

    Repeats least-norm steps until every residual is within the tolerance.

    dx = Jᵀ · (J·Jᵀ + μ·max(scale, 1e-12)·I)⁻¹ · (−r); x ← x + α·dx, α halved until Σr² falls

    Sketch solver solver.js
    • PartCraft
    64-bit
  • Solving a sketch

    Solves the sketch in place and classifies it as under, fully or over defined.

    tol = 1e-9 × max(1, extent)

    Sketch solver solver.js
    • PartCraft
    64-bit
  • Writing the solution back

    Copies the solved variables to the sketch's points, radii and spline end angles.

    angle ← atan2(sin a, cos a)

    Sketch solver solver.js
    • PartCraft
    64-bit
  • Rank, redundancy and determined geometry

    Counts the degrees of freedom left, names relations that repeat or conflict, and marks which entities are fully defined.

    dof = variables − rank; row redundant when its remainder after projection is under 1e-7; variable determined when Σ q_k² > 1 − 1e-6

    Sketch solver solver.js
    • PartCraft
    64-bit
  • Residual: an arc's two ends on one radius

    The equation that keeps an arc's end point at the same distance from the center as its start point.

    f = |e − c| − |s − c|

    Sketch solver sketch.js
    • PartCraft
    64-bit
  • Residuals: parallel and perpendicular

    The equations for two lines being parallel or square to each other.

    parallel: (u × v) ÷ (|u|·|v|); perpendicular: (u · v) ÷ (|u|·|v|)

    Sketch solver sketch.js
    • PartCraft
    64-bit
  • Residuals: tangent

    The equations for a line touching a circle or arc, and for two circles or arcs touching.

    shared end, line and arc: (u · (p − c)) ÷ (|u|·r); shared end, two arcs: ((p − a) × (p − b)) ÷ (rₐ·r_b); else: ±dist(c, line) − r, or d − (rₐ + r_b), or d − ±(rₐ − r_b)

    Sketch solver sketch.js
    • PartCraft
    64-bit
  • Residuals: distance dimensions

    The equations that hold a distance between two points, the length of a line, or the distance from a point or a line to a line.

    f = |b − a| − value; f = sign × signed distance − value

    Sketch solver sketch.js
    • PartCraft
    64-bit
  • Residual: angle dimension

    The equation that holds the angle between two lines at a value in degrees.

    f = atan2(u × v, u · v) − sign × value × π ÷ 180, wrapped to (−π, π]

    Sketch solver sketch.js
    • PartCraft
    64-bit
  • Typed text to a number

    Reads a typed size such as 12.5, ⌀20, R5, 30° or 12 mm as a number.

    Sketch editor: typed sizes and dimension values sketchview.js
    • PartCraft
    64-bit
  • Value shown in the input box

    Opens the input box at a value for the person to accept or change.

    box text = fmt(value) (at most 4 decimals)

    Sketch editor: typed sizes and dimension values sketchview.js
    • PartCraft
    64-bit
  • Applying the typed value

    Takes the text of the input box when it closes and hands the number to whatever asked for it.

    Sketch editor: typed sizes and dimension values sketchview.js
    • PartCraft
    64-bit
  • Changing a dimension's value

    Stores the typed number as the dimension's value.

    0 ≤ value; angle ≤ 180; radius and diameter > 0

    Sketch editor: typed sizes and dimension values sketchview.js
    • PartCraft
    64-bit
  • Keeping a typed size

    Checks a size typed while drawing and keeps it for the shape.

    angle ← ((v mod 360) + 360) mod 360; sweep must be in (0, 360); other sizes > 0

    Sketch editor: typed sizes and dimension values sketchview.js
    • PartCraft
    64-bit
  • Point from typed sizes

    Where the typed length and angle, width and height, diameter, radius or sweep put the next point of the shape being drawn.

    line: a + (cos r, sin r) × len, r = angle × π ÷ 180; rectangle: a ± (w, h); arc end: c + R(sweep) · (s − c)

    Sketch editor: typed sizes and dimension values sketchview.js
    • PartCraft
    64-bit
  • Snap to horizontal or vertical

    Makes a line drawn within 3° of horizontal or vertical exactly so.

    angle° = |atan2(Δy, Δx)| × 180 ÷ π; within 3° of 0, 180 or 90: copy the start's y or x to the end

    Sketch editor: typed sizes and dimension values sketchview.js
    • PartCraft
    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.