Skip to content
AI-Ready Docs
/llms.txt/llms-mcp.txt

Threads, gears and springs ​

Gears, threads and springs are not drawn as sketches and extrusions. The kernel builds each one as a B-rep straight from its defining geometry, in packages/barocss-cad/src/machine/: the involute of a circle for a gear tooth, the ISO profile carried along a helix for a thread, a circle swept along a helix for a spring wire. The studio's Spur gear, Thread and Spring commands and the part model's gear, thread, face-thread and spring features call these builders.

Two of these curves have no exact NURBS form: the involute and the helix. The kernel fits them with cubic pieces, measures the fit's largest distance from the exact curve, and reports it. When the fit would need more pieces than its budget, the builder refuses with PROFILE_BUDGET_EXCEEDED; it never loosens the tolerance (D129). Circles, arcs, planes and the ruling of a band stay exact.

The figures play their steps as you reach them. Use Play/Pause, the arrows or a step's number to go at your own pace; with reduced motion turned on in your system, each step is shown still. They run the kernel's formulas in the page on the kernel's own test cases; each figure's note says what is computed and what is quoted from the built kernel.

1. The involute spur gear ​

A spur gear is set by its module m (mm of reference diameter per tooth), its number of teeth z, its pressure angle α and its face width b. All lengths below are in millimetres (spurGearDimensions, src/machine/gear.ts).

QuantityFormulaTest gear: m 2, z 20
Reference diameter dm z40
Base diameter dbd cos α37.588
Tip diameter dad + 2m + 2xm44
Root diameter dfd − 2.5m + 2xm35
Tooth thickness s on dπm/2 + 2xm tan α, less the thickness reduction3.1416
Half thickness at radius r, as an angleψ(r) = s/d + inv α − inv φ(r), cos φ(r) = rb/rψ(rb) = 0.09344

Here x is the profile shift coefficient (the cutting rack moved out by x m, from −0.5 to 1) and inv φ = tan φ − φ. Only α = 20° is built in this stage. The thickness reduction is this gear's share of a pair's backlash.

An involute spur gear, from its circles to the solid
tip Ø44reference Ø40base Ø37.588root Ø35m 2 · z 20 · α 20°
1. Four circles from three numbers

The module m, the number of teeth z and the pressure angle α fix the gear's circles. This is the kernel's test gear: m = 2 mm, z = 20, α = 20°. The reference (pitch) circle is where two gears roll on each other; the involute flanks grow out of the base circle; the teeth run from the root circle to the tip circle.

d = m z = 40   db = d cos α = 37.588   da = d + 2m = 44   df = d − 2.5m = 35 (mm)
Computed in the page with the kernel's formulas on its test gear (m 2, z 20, α 20°, no shift): the involute, ψ(r), the Hermite fit and its deviation, the rack's tip round and its envelope. The fillet's seven pieces and their deviation are the built kernel's report (spurGearProfile); the page draws the envelope itself. The fitted flank and the involute differ by less than a thousandth of a pixel here, so the fit's error is shown as numbers.

The flank is the only fitted curve in the profile. Its pieces are C¹ Hermite cubics on the roll t, equally spaced, and flankDeviation measures the largest distance from the involute along the circle at each radius, at 65 points a piece. The default tolerance is 10−4 m; the budget is five pieces, the most a side face takes (16 poles). The tip and root arcs are exact rational quadratics, in spans of at most 90°.

Two roots are built:

rootPolicyGeneratorRootReport
schematic-radial (default)spur-gear@0A radial line from the base circle to the root circle when the root lies inside it, then a root arcROOT_TRANSITION_UNVALIDATED warning
generatedspur-gear@1The envelope of the basic rack's tip round (ρ = 0.38 m by default), meeting the involute at the form circle (D130); at least 6 teethgeneratedRoot: form diameter, fillet pieces (up to 15) and their deviation

With a schematic root, a gear with fewer teeth than zmin = 2(1 − x)/sin²α (17.1 at 20°, unshifted) is refused as undercut, naming the shift that would avoid it. A generated root cuts the undercut as the rack would: the involute is trimmed where the tool's envelope crosses it, with an UNDERCUT warning.

A helical gear takes a normal module mn, a helix angle β (above 0, at most 45°) and a hand. Its transverse section is a spur profile with mt = mn / cos β and tan αt = tan αn / cos β; the section turns by z tan β / r as it rises (helixTwist). The turn is a cubic Hermite fit of the rotation eiθ, exact at the piece ends, with at most four pieces in an axial segment and at most 64 segments; its deviation is measured at the tip circle. For mn 2, z 20, β 15° right-hand and b 20, the built kernel reports a twist of 14.83° in one segment of two pieces, 1.66 × 10−5 mm off the exact turn.

2. Two gears in mesh ​

Two external gears mesh when their (normal) modules and pressure angles agree and, if helical, their helix angles are equal and their hands opposite. Otherwise MATE_INCOMPATIBLE. Unshifted, the centre distance is a = m(z1 + z2)/2. Shifted, the working pressure angle solves inv αw = inv α + 2 tan α (x1 + x2)/(z1 + z2) by Newton's method, and a = m(z1 + z2) cos α / (2 cos αw) (workingDistance).

Two spur gears in mesh: the line of action
a = 60m 2 · α 20° · z₁ 20 · z₂ 40
1. Two gears of one module

Gear 1 has 20 teeth, gear 2 has 40, both of module 2 and pressure angle 20°. Unshifted, they mesh at the centre distance where their reference circles touch, at the pitch point; gear 2 turns half as fast, the other way. Two gears whose module, pressure angle or (helical) helix angle and hand do not match are refused (MATE_INCOMPATIBLE).

a = m (z1 + z2) / 2 = 60 mm,   speed ratio −z1/z2 = −0.5
Computed in the page with the kernel's placement and pair formulas on its test pair; the outlines are the exact involute at 15 points a flank (the kernel's sweep uses 150). The sweep's least clearances in step 5 are the built kernel's output (checkSpurGearPair). In step 6 gear 2 keeps its nominal turn, so the gap opens on both sides of its teeth.

spurGearPairNominal gives the formulas alone: centre distance, speed ratio −z1/z2, the ideal contact ratio and the backlash as the sum of the thickness reductions. checkSpurGearPair adds what only geometry can tell:

OutputHow
Working pressure angle, working pitch diameterscos αw = a0 cos α / a, dw1 = 2a z1/(z1 + z2)
Backlashpw − sw1 − sw2 at the working pitch circle; negative when the teeth jam
Tip clearancesa − ra1 − rf2 and a − ra2 − rf1
Usable contact ratiothe path of contact limited to where each flank's involute really starts (the base circle, the form circle, or an undercut's crossing)
Sweepgear 1 through one tooth period at 64 and 128 positions, the two exact outlines (150 points a flank) measured near the mesh; the least clearance refined by golden-section search; converged when both scans agree within max(10−6 m, 2 %)

A crossing is SELF_INTERSECTION with its depth. A usable ratio below the ideal one is reported as a warning. checkPlacedSpurGears takes two gears as they stand in a model, reads the centre distance and the relative phase from their positions and turns, and requires their faces to overlap along the axis.

3. The other gears ​

Each kind has its own builder and its own pair check. All take α = 20° only.

KindFileHow the teeth are built
Internal (ring)gear-internal.tsThe ring's tooth spaces are the teeth of a "space gear" (the shifted rack's gear at x2 + 0.25); that profile is the ring's hole inside a plain rim, built directly, with no Boolean. Root: a schematic corner, or (shaper-cut) the envelope of a pinion-type cutter's tip round, fitted as the rack's. The pair check sweeps in the same sense and tests involute and trochoid interference and radial insertion.
Rackgear-rack.tsThe basic rack itself: straight flanks at α, addendum m, dedendum 1.25 m; flanks, tips and roots are exact planes. A filleted root (radius 0.38 m) is an exact rational arc (an ellipse in a helical rack's transverse section); a helical rack slides its profile along the bar by z tan β, its flat faces still exact planes.
Straight bevelgear-bevel.tsOn every sphere about the apex the tooth is the exact spherical involute of the base cone sin δb = sin δ cos α. The flank is fitted as conic arcs to the involute's stereographic image, lifted back as rational degree-4 curves lying exactly on the sphere; the face is the cone through the apex over that curve. Tip and root are cones, the ends spheres. The only fitted part is the flank, its deviation measured at the heel.
Spiral bevelgear-bevel.tsThe straight gear's spherical section, turned along the cone distance to follow a circular tooth trace; a cubic Hermite fit of that turn. An ideal conjugate pair, flagged IDEAL_MODEL: no face-milling or face-hobbing machine settings.
Wormgear-worm.tsZI (an involute helicoid) or ZA (straight-sided in the axial section, an Archimedean spiral in the transverse one): the section's Hermite fit, twisted along the axis by the helical gear's rotation fit, 1–4 starts, lead angle at most 45°. Section and twist share the tolerance, three quarters and one quarter.
Worm wheelgear-worm.ts, gear-worm-wheel.tsEither a cylindrical helical gear at β = the worm's lead angle (point contact with a ZI worm), or a throated wheel for a ZA worm: in each plane square to the wheel's axis, the envelope of the worm's section in closed form; tip and root are exact tori; flanks and fillets are bicubic Hermite patches, their deviation measured plane by plane.

4. Threads ​

threadSolid (src/machine/thread-solid.ts) builds a modelled ISO metric thread: a threaded rod, a hex head bolt (head and threaded shank in one solid), or a hex nut with a threaded bore. It needs the pitch below half the diameter. The profile is ISO 68-1's basic one (isoThreadRadius); the helical form is in thread-helical.ts.

A modelled thread: the profile swept along a helix
ISO 68-1 profile, one pitchcrest P/8root P/460°PØ6.647Ø8M8 × 1.25 · H = 1.0825 · 5H/8 = 0.6766 mm
1. The ISO 68-1 basic profile

Seen in a plane through the axis, a metric thread repeats every pitch P: a flat crest P/8 wide at the major diameter d, a flank at 30° to the radial direction, a flat root P/4 wide, the other flank; the two flanks of a groove make 60°. Its depth is 5H/8, H = √3/2 · P the height of the 60° triangle. For M8 × 1.25: H = 1.0825 mm, the root at r = 3.3234 mm.

H = √3/2 · P,   rmin = d/2 − 5H/8;   crest |u| ≤ 1/16,   flank 1/16 … 3/8,   root beyond (u the phase within a pitch)
Computed in the page with the kernel's profile, phase, bands, end clip and helix poles on M8 × 1.25, 7.5 mm long. The surface is drawn as 10° pieces of the exact ruled bands, in back-to-front order; the face count, edge degrees and volume are the built kernel's (threadSolid).
FormSurfaceNamesUsed by
helical (the default of threadSolid)half-turn faces, degree (3, 1), ruled between cubic helices; quartic trim curves at the ends.thread#k, .end, .top, .seat, .head, .hex0–.hex5, .bottomthe studio's modelled fasteners; face-thread
facetedone closed mesh of flat facets, the helix sampled every 7.5° round and every P/12 along.facet<k>thread nodes in documents that name no form

The faces' pieces are welded into shared vertices and edges with a tolerance of 10−7 × the part's size, and the solid is validated before it is returned. A nut's faces are turned over (its material is outside its bore), and its thread is pushed out radially by a clearance, 0.04 mm by default (at least 0, below P/4).

The face-thread feature cuts such a thread on a picked cylindrical face of a part (src/part/part-model.ts):

FaceWhat the feature does
A shaftThe shaft is cut down to a core of radius r − 0.8 P over the threaded length; a right-hand helical rod of the shaft's diameter is joined to it. A flat free end lets the thread run out; a shoulder, or a stop inside the face, leaves a relief groove (one pitch wide by default; zero is refused).
A hole (its tap drill)The hole is filled over the length by a plug a pitch wider than the nominal radius, then the rod of the nominal diameter, with the nut's 0.04 mm clearance, is taken out; it runs a pitch past an end where the hole opens onto a face.

A left-hand thread is the right-hand rod mirrored through a plane holding its axis. Each step checks its volume change against the exact value it should have (to 10−7 relative): material in the way is refused as FACE_THREAD_NOT_CLEAR, a face that is not a whole cylinder between two end circles as FACE_THREAD_FACE.

5. Springs ​

helicalSweep (src/machine/spring.ts) sweeps a round wire of radius a along a helix-like centreline C(φ) = (R cos φ, R sin φ, z(φ)). The pitch is constant on a run, or eases from one pitch to the next by a smoothstep in φ, so the wire stays tangent-continuous. The section is the exact circle in the plane normal to C, on the frame e1 toward the axis and e2 = T × e1.

A section point is affine in its (x, y), so each of the circle's four rational quarters is carried along φ by the paths of its three control points. Each path is fitted with cubic Hermite pieces (exact value and derivative at the piece ends). The surface's distance from the exact pipe is a weighted mean of the paths' errors, so the largest path error bounds it: that is the reported deviation, held within 10−4 d by default. A face is degree (2, 3) with at most four pieces. The end discs and the level circles are exact.

For D 20, d 2, five active coils at pitch 6, open ends, the built kernel reports 112 pieces in 28 axial segments, a deviation of 1.84 × 10−4 mm (tolerance 2 × 10−4) and a wire 315.588 mm long.

SpringEnds
Compression, openone run at the body's pitch
Compression, closeda dead coil each end at the geometric solid pitch (the least pitch keeping neighbouring turns d apart), easing to the body's pitch over 90° by default
Compression, closed-groundthe closed spring cut square to the axis at the centreline's end heights by the analytic Boolean: faces .ground0, .ground1
Extension and torsion (hookedSpring)the body close-wound at the solid pitch of a wire d + 2 × tolerance thick; hooks and legs from exact pipe pieces, straight (degree 2 × 1) and bent (the rational torus, degree 2 × 2), glued disc to disc

Where it is in the code ​

FileResponsibility
packages/barocss-cad/src/machine/gear.tsSpur and helical gears: spurGearDimensions, spurGearProfile, flankPoles, flankDeviation, the generated root (rackRoot, filletPoint), extrudedProfile, helixTwist; pairs: spurGearPairNominal, checkSpurGearPair, exactProfile, checkPlacedSpurGears
packages/barocss-cad/src/machine/gear-internal.tsInternal (ring) gears, the shaper-cut root, the internal pair's checks
packages/barocss-cad/src/machine/gear-rack.tsRacks, straight and helical, their filleted root, gear-and-rack checks
packages/barocss-cad/src/machine/gear-bevel.tsStraight and spiral bevel gears on the sphere, their pair
packages/barocss-cad/src/machine/gear-worm.tsZI and ZA worms, the cylindrical wheel pair
packages/barocss-cad/src/machine/gear-worm-wheel.tsThe throated wheel of a ZA worm
packages/barocss-cad/src/machine/thread-solid.tsisoThreadRadius, threadSolid (rod, bolt, nut), the faceted form
packages/barocss-cad/src/machine/thread-helical.tshelicalThreadSolid: helixRow, bandPolygon, cutSpan, the end outlines, assemble
packages/barocss-cad/src/machine/spring.tshelicalSweep, compressionSpring, springSolidPitch, hookedSpring
packages/barocss-cad/src/part/part-model.tsThe face-thread feature
packages/barocss-cad/src/part/part-machine.tsThe thread, gear, spring and other machine features of the part model

How it is checked ​

TestWhat it checks
packages/barocss-cad/test/gear.test.mjsThe test gear's d, db, da, df, the pair's 60 mm and εα 1.6351859636; the solid's volume against the exact profile's area (Green's theorem on the analytic involute) within what the measured deviation allows; fewer pieces for a looser tolerance and the five-piece refusal; the sweep's least clearance j cos αw / 2; KHK's shifted pair (αw 26.0886°, a 56.4999 mm); STEP round trip
packages/barocss-cad/test/gear-generated-root.test.mjs, gear-generated-root-helical.test.mjsThe rack's tool touches the generated profile and never goes in; the form circle by the textbook formula; undercut trimming; the volume from the envelope
packages/barocss-cad/test/gear-helical.test.mjsThe flanks turned along the helix within the measured twist fit; volume; refusals; a meshing helical pair in the part model
packages/barocss-cad/test/gear-internal.test.mjs, gear-internal-shaper.test.mjs, gear-rack.test.mjsThe ring's and the rack's volumes, their pair sweeps (j cos α / 2), interference conditions, meshing in the part model
packages/barocss-cad/test/gear-bevel.test.mjs, gear-bevel-spiral.test.mjs, d150-bevel-pair.test.mjsThe bevel gear's spherical construction, undercut by the exact spherical condition, the pair on the heel sphere
packages/barocss-cad/test/gear-worm.test.mjs, gear-worm-wheel.test.mjsZI and ZA worms, the wheel pairs, the throated wheel's envelope, refusals
packages/barocss-cad/test/thread-solid.test.mjsThe ISO 68-1 profile; rod, bolt and nut, faceted and helical, watertight and near the exact volume; STEP round trip; tessellation shared bit for bit at the corners
packages/barocss-cad/test/face-thread.test.mjs, packages/barocss-cad-model/test/api-face-thread.test.tsShafts with and without relief, tapped holes through and blind, any axis, the left hand as the mirror, refusals with their codes
packages/barocss-cad/test/r12c-spring.test.mjs, r12c-hooked-spring.test.mjsV = πa² × centreline length, the distance from the centreline, each end type's free length, ground ends, hooks and legs, refusals

Limits ​

Refused or approximateCode
A pressure angle other than 20° (every gear kind)UNSUPPORTED_GEAR_KIND
A profile shift outside −0.5 … 1 (spur), −0.5 … 0.75 (internal); an undercut tooth count with a schematic rootUNSUPPORTED_PROFILE_SHIFT
A fit needing more than its budget: 5 flank pieces, 15 fillet pieces, 64 twist segments (worms 128)PROFILE_BUDGET_EXCEEDED
A tooth pointed below its tip, teeth meeting at the rootSELF_INTERSECTION
A bore leaving less than the rim (1 m by default) under the root circle; a geometric margin, not a strength checkBORE_INTERSECTION
Bevel: the Gleason system, shifts, hypoid offsets, crown and internal bevel gears; worms: ZN, ZK, ZC, globoid; throated wheels only for ZA wormsUNSUPPORTED_GEAR_KIND
Roots and profiles are geometry only: every gear report says manufacturingValidated: false—
Threads: ISO metric basic profile only, right hand (a left hand by mirroring in face-thread); a pitch below half the diameter; a thread on mesh facesRangeError, CAPABILITY
The helical thread's helices are cubic quarter circles: up to 2.7 × 10−4 r outside the exact helix (1.1 µm on an M8)—
Springs: round wire, cylindrical body; coils closer than the solid pitch; hooks or legs that come back onto the wireINVALID_INPUT, UNSUPPORTED_SPRING_KIND, COILS_OVERLAP, LEG_OVERLAP

The NURBS pieces these builders produce are ordinary B-spline data; see NURBS curves and surfaces. A face-thread joins or cuts with the curved Boolean.