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
-
Arc angles brought into one turn
Brings an angle into the range from 0 up to 2π before it is written.
r = a mod 2π; r + 2π when r < 0
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Arc
Writes an arc's center, radius and two angles.
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Line
Writes a line's two end points.
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Polyline vertices
Writes the vertices of a lightweight polyline.
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Vertex widths
Writes the start and end width at a polyline vertex.
equal widths: one value, −|width|
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Linetype pattern length
The total length of a linetype's dash pattern.
length = Σ |element length|
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Text direction
The x-axis direction written for a block of text.
x axis = (cos θ, sin θ, 0)
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Block scale
Writes the three scale factors of a block reference in the format's compact form.
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Single-line text
Writes a text's insertion point, height, rotation, width factor and oblique angle.
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Extension record values
Writes the numbers kept in an extension record.
DWG object values written and read dwg/objects-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Block content matrix of a multileader
The 4 × 4 matrix written for a multileader's block content when the model gives none.
M = translate(l) · rotate_z(θ) · scale(s)
DWG object values written and read dwg/mleader-write.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Line read
Reads a line's two end points.
DWG object values written and read dwg/objects-read.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Polyline vertices read
Reads the vertices of a lightweight polyline.
DWG object values written and read dwg/objects-read.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
North direction of older geolocation data
Turns the north angle of a version 1 geolocation object into a direction vector.
north = (sin a, cos a)
DWG object values written and read dwg/objects-read.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Fit point parameters and knots
The parameter of each fit point along the spline, and the knot vector built from them.
u₀ = 0; uᵢ = uᵢ₋₁ + |Qᵢ − Qᵢ₋₁|; knots = [0,0,0,0, u₁ … uₙ₋₂, L,L,L,L]
Spline through fit points dwg/spline-fit.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Cubic basis functions at a parameter
The four B-spline basis values that weigh the control points at one fit point.
Cox–de Boor recurrence, degree 3
Spline through fit points dwg/spline-fit.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Start condition
The rows that pin the first control point and set the spline's start tangent or a natural start.
P₀ = Q₀; P₁ − P₀ = T₀ × u₄ ÷ 3 or P₀ ÷ u₄ − P₁ (1 ÷ u₄ + 1 ÷ u₅) + P₂ ÷ u₅ = 0
Spline through fit points dwg/spline-fit.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
End condition
The rows that pin the last control point and set the spline's end tangent or a natural end.
Pₘ₋₁ = Qₙ₋₁; Pₘ₋₁ − Pₘ₋₂ = T₁ × (L − uₘ₋₁) ÷ 3 or the zero second derivative row
Spline through fit points dwg/spline-fit.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Solve for the control points
Solves the banded system for the x, y and z of every control point.
A · P = B
Spline through fit points dwg/spline-fit.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Lineweight to the file's lineweight index
Picks the stored lineweight that is nearest to the one the layer or object has.
index = the i with the smallest |table[i] − lineweight|
Values changed when a DWG is written dwg/write.jsExact- CadCraft
- ModelCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Ellipse with a ratio above 1
Rewrites an ellipse whose minor axis is longer than its major axis so the file holds a ratio of 1 or less.
major′ = (−m_y, m_x) × ratio; ratio′ = 1 ÷ ratio; start and end − π ÷ 2
Values changed when a DWG is written dwg/write.js64-bit- CadCraft
- ModelCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Ray and construction line direction
Writes the direction of a ray or construction line as a unit vector.
d′ = d ÷ |d|
Values changed when a DWG is written dwg/write.js64-bit- CadCraft
- ModelCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Drawing extents
The lower left and upper right corner of model space written to the file header.
min and max of x, y, z over the defining points
Values changed when a DWG is written dwg/write.js64-bit- CadCraft
- ModelCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Default angles of a light
The hotspot and falloff angles written for a light that has none of its own.
hotspot = π ÷ 4; falloff = π ÷ 4 + 0.0872664626
Values changed when a DWG is written dwg/solid-write.js64-bit- CadCraft
- ModelCraft
- CivilCraft
- DetailCraft
- PartCraft
-
Day of the year
The day number of a date.
N = days before the month + day (+1 after February in a leap year)
Sun position for shadows m3d/sun.jsExact- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
-
Equation of time and declination
How far sun time runs ahead of clock time, and the sun's angle above the equator, for the date.
γ = 2π ÷ (365 or 366) × (N − 1 + (hour − 12) ÷ 24); eqtime = 229.18 × (0.000075 + 0.001868 cos γ − 0.032077 sin γ − 0.014615 cos 2γ − 0.040849 sin 2γ)
Sun position for shadows m3d/sun.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
-
Hour angle and altitude
The sun's height above the horizon.
tst = hour × 60 + eqtime + 4 × lon − 60 × tz; H = tst ÷ 4 − 180°; cos Z = sin φ sin δ + cos φ cos δ cos H; altitude = 90° − Z
Sun position for shadows m3d/sun.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
-
Azimuth
The sun's compass direction, in degrees clockwise from north.
azimuth = atan2(sin H, cos H sin φ − tan δ cos φ) + 180°, wrapped to 0…360
Sun position for shadows m3d/sun.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
-
Direction toward the sun
The unit vector shadows are cast from, in model axes (north is +Y, east is +X).
dir = (sin a cos alt, cos a cos alt, sin alt)
Sun position for shadows m3d/sun.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
-
Unit vector
A vector scaled to length 1.
n = a ÷ |a|; [0, 0, 0] when |a| ≤ 1e-15
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Polygon normal
The unit normal of a polygon given by its corner points.
N = Σ (pᵢ − pᵢ₊₁) × (pᵢ + pᵢ₊₁) taken per axis, then normalized
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Polygon area in 3D
The area of a flat polygon in space.
area = |Σ (pᵢ − pᵢ₊₁) × (pᵢ + pᵢ₊₁)| ÷ 2
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Plane through a point
A plane as a unit normal and an offset, with the normal's sign made canonical.
n·p = d; first component of n with |n| > 1e-9 is made positive
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Same plane test
Whether two planes are the same plane.
|n₁·n₂| > 1 − 1e-9 and |d₁ × sign(n₁·n₂) − d₂| ≤ 1e-6
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Closest points of a line and a segment
The nearest points between a ray's line and an edge.
den = (d·d)(u·u) − (d·u)²; t = (B·E − C·D) ÷ den; s = (A·E − B·D) ÷ den, clamped to [0, 1]
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Closest points of two lines
The nearest points between two infinite lines, or nothing when they are parallel.
den = A·C − B²; parallel when |den| < 1e-14 × A × C
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Ray and plane
The point where a ray's line meets a plane.
t = (d_plane − n·o) ÷ (n·dir); p = o + t × dir
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Ray and triangle
The distance along a ray to a triangle, or nothing when it misses.
Möller–Trumbore: det = e₁·(d × e₂); u, v, t from three scalar triple products ÷ det
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Rotation about an axis through a point
The 4×4 matrix that turns geometry by an angle about an axis through a given point.
M = T(about) × R(axis, θ) × T(−about), R from Rodrigues' formula
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Transform a point
A point moved by a 4×4 matrix.
p′ = (M × [x, y, z, 1]) ÷ w
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Inverse of a 4×4 matrix
The matrix that undoes a transform, used to move points into a group's own coordinates.
M⁻¹ = adj(M) ÷ det(M), with det from twelve 2×2 minors
3D vectors, planes and transforms m3d/vec.js64-bit- CadCraft
- BimCraft
- ModelCraft
- TakeoffCraft
- CivilCraft
-
Line fit
The best straight line through a run of center-line pixels, and how far the worst pixel lies from it.
θ = ½ × atan2(2·Sxy, Sxx − Syy); ends = feet of the first and last points on the line through the centroid
Tracing a scan into lines and arcs raster/trace.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
- PartCraft
-
Circle fit
The best circle through a run of center-line pixels, its sweep and the angles of an arc.
Kåsa: solve the 2 × 2 system for the center about the centroid, r = √(uc² + vc² + (Suu + Svv) ÷ n); then Gauss-Newton on d − r
Tracing a scan into lines and arcs raster/trace.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
- PartCraft
-
Corner detection
Where a chain of pixels turns sharply, so it can be cut there before fitting.
turn = |atan2(r − q) − atan2(q − p)| over ± w steps; corner when turn ≥ 0.6 rad and largest nearby
Tracing a scan into lines and arcs raster/trace.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
- PartCraft
-
Splitting a chain into lines and arcs
Fits a line, else an arc, else splits the chain at the point farthest from its chord, and joins neighbors that fit as one.
distance to chord = |(P − A) × (B − A)| ÷ |B − A|
Tracing a scan into lines and arcs raster/trace.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
- PartCraft
-
Joining collinear lines
Merges two lines that lie on the same straight line and nearly touch.
Tracing a scan into lines and arcs raster/trace.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
- PartCraft
-
Squaring level and plumb lines
Makes nearly horizontal and vertical lines exactly so, and gives lines of one wall the same coordinate.
y = (y₁ + y₂) ÷ 2; shared coordinate = Σ(coordinate × length) ÷ Σ length
Tracing a scan into lines and arcs raster/trace.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
- PartCraft
-
Closing corners
Moves a line end to the point where its line meets a nearby line.
s = ((B₁ − E) × v) ÷ (u × v); new end = E + s·u
Tracing a scan into lines and arcs raster/trace.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
- PartCraft
-
Lines and arcs in image coordinates
The traced lines and arcs with the window offset added and the arc end points worked out.
start = (cx + r·cos a₀, cy + r·sin a₀); end = (cx + r·cos a₁, cy + r·sin a₁)
Tracing a scan into lines and arcs raster/trace.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
- PartCraft
-
Crossing of two traced lines
The point where two traced line segments cross.
d = (a₂ − a₁) × (b₂ − b₁); t = ((b₁ − a₁) × (b₂ − b₁)) ÷ d; point = a₁ + t·(a₂ − a₁)
Tracing a scan into lines and arcs raster/snap.js64-bit- CadCraft
- BimCraft
- ModelCraft
- CivilCraft
- PartCraft
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.