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.
Calculations
-
Constraint equations
The residual of each constraint: how far the current geometry is from meeting it.
coincident: P₀ − P₁; distance: |P₁ − P₀| − d; parallel: (u × v) ÷ (|u|·|v|); tangent: distance(center, line) − r; angle: atan2(u × v, u·v) − θ·π ÷ 180
2D constraint solver gsolve.js64-bit- CadCraft
-
Circle of a polyline arc segment
The center and radius of a polyline's arc segment as the solver sees it.
θ = 4·atan(b); r = |c ÷ (2·sin(θ ÷ 2))|; h = ± r·cos(θ ÷ 2); center = chord midpoint + normal × h
2D constraint solver gsolve.js64-bit- CadCraft
-
Derivatives
How each equation changes with each coordinate it depends on.
∂f/∂x ≈ (f(x + h) − f(x − h)) ÷ 2h, h = 1e-6 × max(1, |x|)
2D constraint solver gsolve.js64-bit- CadCraft
-
Cholesky solve
Solves the damped normal equations for one step.
A = L·Lᵀ; L·y = b; Lᵀ·z = y
2D constraint solver gsolve.js64-bit- CadCraft
-
Newton iteration
Repeats damped least-norm steps until every equation is met.
(J·Jᵀ + μ·max(scale, 1e-12)·I)·y = −r; dx = Jᵀ·y; x ← x + α·dx, α = 1, ½, ¼ …
2D constraint solver gsolve.js64-bit- CadCraft
-
Writing the solution back
The changed objects after a solve, and the remaining residual.
residual = √(Σ rᵢ²)
2D constraint solver gsolve.js64-bit- CadCraft
-
Radius sign and arc angles
Puts solved values back into an object in its stored form.
2D constraint solver gsolve.js64-bit- CadCraft
-
Degrees of freedom and redundant constraints
How many independent constraints there are, which ones add nothing, which conflict and which objects are fully fixed.
v = row ÷ |row|; v ← v − (v·b)·b for each kept row b, twice; redundant when |v| < 1e-7; degrees of freedom = variables − rank
2D constraint solver gsolve.js64-bit- CadCraft
-
Arcs as straight pieces
The points that stand in for an arc or circle in a hatch boundary.
n = max(4, ⌈|sweep| ÷ (2π ÷ 128)⌉); point = c + r·(cos a, sin a)
Hatch boundaries and pattern lines hatch.js64-bit- CadCraft
-
A closed object as a boundary
The boundary loop of a circle, a closed polyline or a full ellipse picked as an object.
Hatch boundaries and pattern lines hatch.js64-bit- CadCraft
-
Boundary tolerance
The distance within which boundary pieces count as touching.
tol = 1e-9 × max(width, height, 1)
Hatch boundaries and pattern lines hatch.js64-bit- CadCraft
-
Where two boundary pieces cross
The parameters at which two segments cross or touch, so each can be split there.
u = ((c − a) × q) ÷ (r × q); v = ((c − a) × r) ÷ (r × q)
Hatch boundaries and pattern lines hatch.js64-bit- CadCraft
-
Merging boundary corners
The corner points of the boundary, with points that nearly coincide made one.
snap = 1000 × tol; split point = start + (end − start)·t
Hatch boundaries and pattern lines hatch.js64-bit- CadCraft
-
Faces and their areas
Every closed region the boundary pieces make, with the signed area used to choose among them.
area = ½ Σ (xᵢ·yᵢ₊₁ − xᵢ₊₁·yᵢ)
Hatch boundaries and pattern lines hatch.js64-bit- CadCraft
-
Point inside a face
Whether the picked point, or an island, lies inside a face.
Hatch boundaries and pattern lines hatch.js64-bit- CadCraft
-
Pattern scale and angle
The pattern's line families at the hatch's scale, angle and origin.
k = scale ÷ (1 metric, 25.4 inch); origin = R(angle)·(x, y)·k; spacing and dashes × k
Hatch boundaries and pattern lines hatch.js64-bit- CadCraft
-
Pattern lines clipped to the boundary
The dashes of every pattern line that fall inside the hatch.
line k origin = O + k·(dx·u + dy·n); crossing: t = d₁ ÷ (d₁ − d₂) along an edge
Hatch boundaries and pattern lines hatch.js64-bit- CadCraft
-
Rounding of stored values
The two rounding helpers every stored number of an item goes through.
r4(v) = round(v × 10000) ÷ 10000; r2(v) = round(v × 100) ÷ 100
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Block to millimeters
The transform from a block's own coordinates and units to the item's millimeters.
M = [mm, 0, 0, mm, −base.x·mm, −base.y·mm]; scale of a transform = √|det|; angle = r4(atan2(y, x) in degrees)
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Lines, circles and arcs of a block
A block's lines, circles and arcs as plan entities in millimeters.
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Nested block references
The transform of a block reference inside the block, with its rows and columns.
local = T(insert) · R(rotation) · S(sx, sy) · T(−base + column·spacing ÷ sx, row·spacing ÷ sy)
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Mesh body from a block's 3D faces
The item's 3D body and height when the block holds 3D faces.
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Arcs as points, 5° steps
The points that replace a circle or arc that cannot stay an arc.
n = max(8, ⌈sweep ÷ 5°⌉); point = c + r·(cos a, sin a)
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Splines as points
The points that replace a block's spline in the item's plan.
de Boor recurrence at u = lo + (hi − lo)·s ÷ n, n = max(16, 8 × control points)
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Arc points for bounds
The points of an arc used to find a plan's bounds.
n = max(4, ⌈sweep ÷ 10°⌉); point = c + r·(cos a, sin a)
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Bounds of a plan
The box round an item's plan, from which its width and depth are taken.
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Box body on a plan
A box body standing on the plan's bounds with a given height.
w = max x − min x; d = max y − min y; each of x, y, z, w, d, h rounded to 4 decimals
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Item from a mesh file
A mesh file's triangles as an item body in millimeters, with its footprint and sizes.
p = file point × unit in mm; Y-up: (x, y, z) → (x, −z, y); stored = r4(p − (center x, max y, min z))
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
STL corners
The corner points of an STL file's triangles.
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
glTF accessor values
The numbers of a glTF position or index accessor.
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
glTF node transforms
The matrix that places each glTF node's mesh.
M = T · R(q) · S, R from the quaternion (qx, qy, qz, qw)
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Convex hull footprint
The outline round a mesh item's points, used as its plan.
monotone chain; turn = (a − o) × (b − o), popped when ≤ 0
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Box of a body
The box a body fills: a box body itself, or the extent of a mesh body.
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Box item from width, depth and height
The rectangle plan and box body of an item given only by its sizes.
x from −w ÷ 2 to +w ÷ 2; y from −d to 0; label height = min(0.18 d, 150), reduced to fit 90% of w
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Sizes from attributes
Width, depth and height read from a block's attributes.
Library item geometry from blocks, meshes and tables libitem.js64-bit- CadCraft
- BimCraft
-
Meters per drawing unit
The table that converts drawing units to the 3D model's meters.
inch 0.0254; foot 0.3048; yard 0.9144; mile 1609.344; no unit 0.001
3D solids, faces and units in a drawing model3d.jsExact- CadCraft
-
Outline of a closed 2D object
The ring of points a solid is extruded from, and its area.
circle: 48 points at radius r; arc: steps of at most 7.5°; area = ½ |Σ (xᵢ·yᵢ₊₁ − xᵢ₊₁·yᵢ)|
3D solids, faces and units in a drawing model3d.js64-bit- CadCraft
-
Extruded solid
A solid made by pushing a ring up or down by a height.
local ring = ring − (min x, min y); placed at (min x, min y, z₀)
3D solids, faces and units in a drawing model3d.js64-bit- CadCraft
-
Cylinder
A cylinder from a center, radius and height.
3D solids, faces and units in a drawing model3d.js64-bit- CadCraft
-
Volume of each solid
The volume listed for every closed solid.
volume = |V of the definition| × |det of the placement's 3 × 3 part|
3D solids, faces and units in a drawing model3d.js64-bit- CadCraft
-
Changing the drawing's units
Scales the 3D model so it stays the same size on the drawing when the units change.
ratio = m per new unit ÷ m per old unit; every vertex and placement offset × ratio
3D solids, faces and units in a drawing model3d.js64-bit- CadCraft
-
3D faces written to a file
The model's faces as 3D faces in drawing units for DWG and DXF.
file point = placed vertex in meters ÷ k, k = meters per drawing unit
3D solids, faces and units in a drawing model3d.js64-bit- CadCraft
-
3D faces inside blocks
Places the 3D faces a block holds once for every reference of that block.
(x′, y′) = M·(x, y); z′ = z
3D solids, faces and units in a drawing model3d.js64-bit- CadCraft
-
3D faces read from a file
A file's loose 3D faces brought into the model in meters.
corner in meters = file corner × k
3D solids, faces and units in a drawing model3d.js64-bit- CadCraft
-
Underlay shapes and text
The underlay's paths as plotted segments and fills, and its text.
B(t) = (1 − t)³·P₀ + 3(1 − t)²t·P₁ + 3(1 − t)t²·P₂ + t³·P₃, t = s ÷ 8; line width = max(0.05, w × √|det|); text height = h × √|det| ÷ FONT_EM
PDF underlay in a plot pdf-emit.js64-bit- CadCraft
-
Finding the paper
The four corners of the sheet of paper in the photo.
corner = (pixel + 0.5) × k on a copy reduced by the whole factor k; fill = bright pixels inside ÷ outline area
Sketch photo to drawing photosketch.js64-bit- CadCraft
-
Perspective matrix from four corners
The 3 × 3 matrix that takes the straight sheet's corners to the corners found in the photo.
8 equations in h₁ … h₈ with h₉ = 1, solved by Gauss–Jordan elimination
Sketch photo to drawing photosketch.js64-bit- CadCraft
-
Applying the perspective matrix
Where a point of the straight sheet lies in the photo.
w = h₇x + h₈y + h₉; x′ = (h₁x + h₂y + h₃) ÷ w; y′ = (h₄x + h₅y + h₆) ÷ w
Sketch photo to drawing photosketch.js64-bit- CadCraft
-
Sheet proportions
The long-to-short side ratio of the straightened sheet.
w = mean of top and bottom; h = mean of left and right; ratio = max ÷ min
Sketch photo to drawing photosketch.js64-bit- CadCraft
-
Drawing units per pixel
The size of one pixel of the straightened sheet in drawing units.
units per px = long side (mm) ÷ long side (px) × scale ÷ mm per unit
Sketch photo to drawing photosketch.js64-bit- CadCraft
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.