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

  • Line and line

    The parameters at which two lines cross.

    den = d₁ × d₂; tₐ = (w × d₂) ÷ den; t_b = (w × d₁) ÷ den, w = B.a − A.a

    Sketch intersections of lines, arcs and circles sketch-intersect.js
    • PartCraft
    64-bit
  • Line and circle

    The parameters along a line at which it crosses a circle.

    A·t² + B·t + C = 0; q = −½·(B + sign(B)·√(B² − 4AC)); t₁ = q ÷ A, t₂ = C ÷ q

    Sketch intersections of lines, arcs and circles sketch-intersect.js
    • PartCraft
    64-bit
  • Circle and circle

    The points where two circles cross.

    a = (r₁² − r₂² + d²) ÷ 2d; h = √(r₁² − a²); points = c₁ + a·û ± h·û⊥

    Sketch intersections of lines, arcs and circles sketch-intersect.js
    • PartCraft
    64-bit
  • Is a crossing on the bounded curve

    Decides whether a crossing lies on the drawn part of a line or arc, and snaps it to the end when it is within the tolerance.

    line: −eps ÷ L ≤ t ≤ 1 + eps ÷ L; arc: angle ≤ sweep + eps ÷ r

    Sketch intersections of lines, arcs and circles sketch-intersect.js
    • PartCraft
    64-bit
  • Crossing points of two curves

    All crossing points of two sketch curves, sorted along the first.

    eps = 1e-9 × max(1, size of A, size of B); duplicates within 10 × eps removed

    Sketch intersections of lines, arcs and circles sketch-intersect.js
    • PartCraft
    64-bit
  • Knot span of a parameter

    Finds which knot span a parameter falls in.

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    Exact
  • Basis functions

    The values of the B-spline basis functions that are not zero at a parameter.

    t = N[r] ÷ (right[r+1] + left[j−r]); N[r] = saved + right[r+1] × t; saved = left[j−r] × t (Cox–de Boor)

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    64-bit
  • Basis function derivatives

    The basis functions and their derivatives up to a given order at a parameter.

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    64-bit
  • Point on a spline

    The point of a spline at a parameter.

    C(u) = Σⱼ Nⱼ(u) × Pⱼ (degree + 1 terms)

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

    The point, tangent and higher derivatives of a spline at a parameter.

    C⁽ⁱ⁾(u) = Σⱼ Nⱼ⁽ⁱ⁾(u) × Pⱼ

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    64-bit
  • Chord-length parameters

    Gives each fit point a parameter equal to the summed straight distances up to it.

    tᵢ = tᵢ₋₁ + |Qᵢ − Qᵢ₋₁|

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    64-bit
  • Dense linear solve

    Solves the linear system that gives a fit spline its poles.

    A · X = B by Gauss–Jordan elimination with partial pivoting

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    64-bit
  • Spline through fit points

    The cubic spline that passes through the given points, open with natural or given end directions, or closed and periodic.

    rows: C(tᵢ) = Qᵢ; ends: C″ = 0 or C′ = (cos a, sin a); solve for the poles

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

    The area term of a spline by Green's formula: the enclosed area when the spline is closed.

    ½ ∫ (x·y′ − y·x′) du, 3-point Gauss–Legendre per knot span (nodes ±√(3 ÷ 5), 0; weights 5/9, 8/9, 5/9)

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

    The signed curvature of a spline at a parameter.

    κ = (x′·y″ − y′·x″) ÷ |C′|³

    Sketch splines: evaluation, fitting and exact pieces sketch-spline.js
    • PartCraft
    64-bit
  • 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
  • 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
  • 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
  • Point snapped onto a curve

    The nearest point on a line, circle, arc or spline to the pointer, used when a new point snaps onto a curve.

    line: a + t·d, t = ((p − a) · d) ÷ (d · d); circle: c + (p − c) × r ÷ |p − c|

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

    Scales a vector to length 1.

    a ÷ |a|

    Vectors, plane frames and transforms vec.js
    • PartCraft
    64-bit
  • Frame of a plane

    The origin and the x, y and normal axes given to a sketch plane.

    o = (p·n) n; x = Y × n (or world X made square to n when |n_y| > 0.9); y = n × x

    Vectors, plane frames and transforms vec.js
    • PartCraft
    64-bit
  • Sketch point to model space

    The 3D position of a sketch point (u, v) on its plane.

    p = o + u x + v y

    Vectors, plane frames and transforms vec.js
    • PartCraft
    64-bit
  • Model point to sketch coordinates

    The sketch coordinates of a 3D point on a plane.

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

    Vectors, plane frames and transforms vec.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.