Most browser calculators for home interiors reduce 3D spaces to flat lookup tables ("needs 10 ft ceiling"). Lookup tables fail the moment a real homeowner has a sloped garage-door track dropping 12 inches at the back wall, an offset hitting mat in a 10-foot-wide spare room, or a short-throw projector ceiling mount positioned 9 feet from the screen.
You can solve both biomechanical swing collision and optical shadow-cone intersection analytically in pure TypeScript at 60 FPS without any physics engine or GPU readback. Here is the clean 3D geometric formulation we use inside browser-native CAD tools.
1. Coordinate Convention
Pick one unambiguous right-handed architectural coordinate system in inches and keep every module on it:
-
X(width):0at room center,-roomWidth / 2= left wall,+roomWidth / 2= right wall. -
Y(depth):0at the impact screen face, increasing back toward the rear wall (+roomDepth). -
Z(height):0at concrete slab / subfloor,+roomHeightat finished ceiling.
All hardware specs (hitting mat thickness matZ, lateral tee offset teeX, ball-to-screen distance teeY, projector mount (projX, projY, projZ)) live in the exact same coordinate frame.
2. Modeling the Swept Golf Swing Envelope
A golfer's swing path is not a sphere centered on the ball. It is a tilted circular arc swept around a shoulder pivot P_hub, inclined at the club's swing-plane angle theta (roughly 46 to 50 degrees for a 45.5" driver, steeper ~58 degrees for an iron).
export interface SwingSample { x: number; y: number; z: number; phase: 'backswing' | 'impact' | 'followthrough'; } export function sampleSwingArc(params: { golferHeightIn: number; clubLengthIn: number; matThicknessIn: number; teeX: number; teeY: number; handedness: 'right' | 'left'; }): SwingSample[] { const { golferHeightIn, clubLengthIn, matThicknessIn, teeX, teeY, handedness } = params; const sign = handedness === 'right' ? 1 : -1; // Shoulder pivot sits roughly 0.81 * height above the hitting mat, offset behind ball along X const hubZ = matThicknessIn + golferHeightIn * 0.81 - 6.5; const hubX = teeX - sign * 24; const hubY = teeY; // Effective arm + club radius const radius = golferHeightIn * 0.36 + clubLengthIn * 0.88; const planeTiltRad = (48 * Math.PI) / 180; const samples: SwingSample[] = []; for (let deg = -140; deg <= 145; deg += 5) { const phi = (deg * Math.PI) / 180; // Parametric arc in tilted plane passing through the ball at phi = 0 const localU = Math.sin(phi) * radius; const localV = (1 - Math.cos(phi)) * radius; const x = teeX - sign * (localV * Math.cos(planeTiltRad) * 0.55); const y = hubY + localU; const z = matThicknessIn + localV * Math.sin(planeTiltRad); samples.push({ x, y, z, phase: deg < -15 ? 'backswing' : deg > 15 ? 'followthrough' : 'impact' }); } return samples; } Once you have the discrete parametric arc (58 points, computed in < 0.05 ms), checking collisions against every room constraint is trivial and exact:
- Ceiling clearance:
min(roomHeight - p.z)across all points. - Left/right drywall clearance:
min(roomWidth / 2 - Math.abs(p.x))— immediately revealing why shiftingteeXby+15"in a 10-foot room gains over 15 inches of critical backswing clearance on the golfer's rear wall. - Overhead garage-door track clearance: Model horizontal door tracks as an axis-aligned box spanning
[trackStartY, roomDepth]at heightroomHeight - trackDropIn(12"for standard radius tracks vs4"for high-lift tracks) and compute signed clearance against every arc point inside the track footprint.
3. Optical Projector Frustum & Golfer Shadow Ray-Tracing
A projector mounted at L = (projX, projY, projZ) projects an image onto the screen plane Y = 0, spanning X in [-screenW/2, +screenW/2] and Z in [screenBottomZ, screenTopZ].
A golfer standing at the hitting mat occupies a bounding silhouette (head + torso + lead shoulder) centered at G = (teeX - sign * 24, teeY, matThicknessIn) up to height headZ = matThicknessIn + golferHeightIn.
To check whether the golfer casts any shadow onto the active impact screen, you do not need a WebGL shadow map. Use exact projective ray intersection!
For the top of the golfer's head (Z = headZ, Y = teeY):
- Trace the ray from the projector lens
Lthrough the golfer's head crownH = (golferX, teeY, headZ)forward to the screen planeY = 0:- Parametric step
t = projY / (projY - teeY)(only casts a forward shadow whenprojY > teeY, i.e., projector is behind the golfer!). - Screen hit height
shadowTopZ = projZ + t * (headZ - projZ). - Screen hit lateral position
shadowX = projX + t * (golferX - projX).
- Parametric step
- Check overlap with the active projected image rectangle
[-screenW/2, +screenW/2] x [screenBottomZ, screenTopZ]:- If
projY <= teeY(projector mounted slightly in front of the golfer, common with0.50to0.72short-throw lenses), shadow intrusion is identically0.0". - If
projY > teeYandshadowTopZ > screenBottomZandMath.abs(shadowX) < screenW / 2 + 10, the vertical shadow intrusion onto the screen isshadowTopZ - screenBottomZinches.
- If
export function computeShadowIntrusionIn(params: { projY: number; projZ: number; teeY: number; golferHeadZ: number; screenBottomZ: number; }): number { const { projY, projZ, teeY, golferHeadZ, screenBottomZ } = params; // Projector mounted in front of or directly above golfer casts zero forward shadow if (projY <= teeY + 6) return 0; const t = projY / (projY - teeY); const projectedHeadZ = projZ + t * (golferHeadZ - projZ); return Math.max(0, projectedHeadZ - screenBottomZ); } 4. Why Pure Analytical Solvers Beat Lookup Tables
Because the entire swing + optical + enclosure solver is stateless TypeScript with zero DOM dependency:
- It runs identically in real-time reactive sliders (Svelte 5
$derived) AND inside deterministic Vitest regression suites. - Every UI slider drag (changing room width from
120"to144", switching from standard tracks to high-lift tracks, or swapping a0.69throw ratio BenQ AK700ST for a0.90TK700STi) re-solves the entire 3D room in less than 0.2 milliseconds. - The exact same engine powers embeddable calculators with zero server round-trips.
We built this exact solver into SimBayCAD (including its free embeddable Room-Fit & Throw Widget) so builders can inspect both the 3D swing arc and optical ray-trace live before cutting a single length of 1" EMT conduit.
