gearSDF: Parametric Mechanical Gear Distance Field
Complex Radial Tooth Geometry Through Hyperbolic Functions
The gearSDF
function generates signed distance fields for mechanical gear shapes with parametrically controlled teeth. The function employs hyperbolic tangent modulation to create precise tooth profiles based on angular position and gear parameters.
Mathematical Foundation
The gear distance calculation combines radial base geometry with hyperbolic tooth modulation:
where the base distance is:
and the teeth modulation uses hyperbolic functions:
The parameter mapping follows:
Function Signature
Parameter | Type | Description |
---|---|---|
st | vec2 | 2D coordinate position |
b | float | Base radius and teeth sharpness control |
N | int | Number of gear teeth |
Implementation Demonstrations
Live Editor
const fragment = () => Scope(() => { const gearSystem = float(1000).toVar() Loop(4, ({ i }) => { const angle = i.toFloat().mul(1.57) const offset = vec2(angle.sin().mul(0.25), angle.cos().mul(0.25)) const rotation = iTime.mul(i.add(1).toFloat()) const rotatedUV = vec2( uv.x.sub(0.5).mul(rotation.cos()).sub(uv.y.sub(0.5).mul(rotation.sin())).add(0.5), uv.x.sub(0.5).mul(rotation.sin()).add(uv.y.sub(0.5).mul(rotation.cos())).add(0.5) ) const teeth = int(i.mul(2).add(6)) const size = i.toFloat().mul(0.5).add(2) const d = gearSDF(rotatedUV.add(offset), size, teeth) gearSystem.assign(gearSystem.min(d)) }) const brightness = gearSystem.step(0).mul(0.9).add(float(0.02).smoothstep(0, gearSystem.abs()).mul(0.4)) return vec4(brightness.mul(vec3(0.7, 0.5, 0.3)), 1) })