Dev.to WebDev 🛠 Dev 👁 2 📖 4 min read

Ray-Tracing Projector Shadows and Garage Door Track Collisions in Pure TypeScript

When someone builds an indoor golf simulator in a residential garage, the three most expensive mistakes are purely geometric: Mounting a short-throw projector 18 inches too far back so the golfer's head and lead should

When someone builds an indoor golf simulator in a residential garage, the three most expensive mistakes are purely geometric:

  1. Mounting a short-throw projector 18 inches too far back so the golfer's head and lead shoulder cast a permanent silhouette across the lower third of the impact screen.
  2. Forgetting that 1-inch trade-size EMT conduit actually has a 1.163-inch outer diameter (plus 1.5 to 2.0 inches of bungee gap per side), shrinking the viewable impact screen enough to throw off a fixed-lens projector's throw ratio.
  3. Measuring the ceiling height in the middle of the garage while ignoring a standard 15-inch drop garage door track or overhead opener rail hanging right over the driver's follow-through arc.

Rather than relying on rough rules of thumb or an LLM guess, we built a deterministic TypeScript optics and biomechanics solver inside SimBayCAD (raycast-optics.ts and swing-biomechanics.ts) that runs in under 1 ms on every slider change in the browser.

Here is how the math breaks down.

1. Exact Viewable Screen Geometry From Trade-Size EMT Pipe

A "10 ft x 8 ft" DIY enclosure frame built from 1-inch EMT conduit does not give you a 120" x 96" projected image. You lose pipe outer diameter plus bungee clearance on every clamped edge:

export const EMT_1IN_OD_IN = 1.163;

export function computeViewableScreenSize(enclosure: EnclosureSpec): ViewableScreenDimensions {
  const sideDeductionPerSide = EMT_1IN_OD_IN + enclosure.screenGapPerSideIn;
  const bottomDeduction =
    enclosure.bottomEdgeType === 'bottom_emt_pipe'
      ? EMT_1IN_OD_IN + enclosure.screenGapPerSideIn
      : 1.5; // weighted hem skirt with no bottom rail

  const viewableScreenWidthIn = Math.max(24, enclosure.outerWidthIn - 2 * sideDeductionPerSide);
  const viewableScreenHeightIn = Math.max(24, enclosure.outerHeightIn - sideDeductionPerSide - bottomDeduction);
  const diagonalIn = Math.hypot(viewableScreenWidthIn, viewableScreenHeightIn);

  return { viewableScreenWidthIn, viewableScreenHeightIn, diagonalIn };
}

At 1.163" pipe OD and 1.5" bungee gap per side, a 120" x 96" outer frame drops to 114.67" x 91.84" viewable image area. That 5.3-inch width reduction changes the throw distance of a 0.69-throw short-throw projector by nearly 4 inches and shifts vertical image alignment.

2. Projective 3D Shadow Raycasting Onto the Impact Screen

Once we solve the projector's lens height lensY, lateral mount coordinate mountX, and longitudinal throw plane mountZ = screenZ + recommendedThrowDistanceIn (balancing optical zoom limits, ceiling bracket clearance, and vertical keystone angle), we project 3D golfer occluder points (gx, gy, gz) onto the impact screen plane z = screenZ:

// Any 3D occluder point (gx, gy, gz) with screenZ < gz < mountZ projects onto z = screenZ at:
//   t  = (mountZ - screenZ) / (mountZ - gz)
//   sx = mountX + (gx - mountX) * t
//   sy = lensY  + (gy - lensY)  * t

Why sample multiple (gx, gz) points instead of a single center dot?

  • A right-handed golfer's stance center sits roughly 20 inches left of the tee (teeX - 20), while a left-handed golfer sits teeX + 20.
  • During address and early follow-through, the lead shoulder and extended arms pass slightly forward of the ball (ballToScreenIn - 14), while the back of the head and torso sit slightly behind it (ballToScreenIn + 14).
  • Effective golfer head height includes the hitting mat thickness (golferAddressHeightIn = golfer.matThicknessIn + golfer.heightIn * 0.93).

For every sampled (gx, gy, gz) between the lens and the screen, if sx falls within the projected image bounds [imgLeft, imgRight], the projected shadow height sy above the bottom of the screen tells us immediately whether the golfer blocks the image and by how many inches.

When a room's ceiling forces a downward keystone tilt (ceiling_too_low or ceiling_too_high), the solver automatically slides the recommended mount toward the shortest shadow-free edge of the projector's optical zoom window (shadowFreeLimitIn = golfer.ballToScreenIn - 10) before computing verticalKeystoneDeg = atan2(verticalDeficitIn, recommendedThrowDistanceIn) * 180 / PI.

3. Sloped Ceilings and Overhead Garage Door Track Obstacles

Garage ceilings are rarely flat boxes. Many have a slight pitch toward the garage door plus overhead sectional door tracks hanging 12 to 15 inches below the joists.

In swing-biomechanics.ts, we evaluate the true ceiling height at any longitudinal coordinate z along the hitting bay:

export function ceilingHeightAtZIn(room: RoomSpec, zFromBackWallIn: number): number {
  if (room.ceilingSlopeDeg === 0) return room.ceilingHeightIn;
  const rad = (room.ceilingSlopeDeg * Math.PI) / 180;
  const delta = zFromBackWallIn * Math.tan(rad);
  return clamp(room.ceilingHeightIn + delta, 72, room.ceilingHeightIn + 48);
}

Then evaluateOverheadAtSwing() checks whether the golfer's 80-inch longitudinal swing corridor ([ballZ - 40, ballZ + 40]) intersects:

  • standard_15in sectional tracks (rawDropIn = Math.max(12, room.garageTrackDropIn || 15))
  • high_lift tracks (hugging within 4 to 5 inches of the ceiling and terminating further toward the door)
  • roll_up drums (14-inch drop confined to the final 18 inches near the door header)

Instead of a binary "9-foot ceiling OK" badge, the engine catches the exact scenario where a 9'6" garage ceiling becomes an 8'3" effective clearance once the sectional garage track drops into the follow-through plane.

Try the Interactive Solver

Every calculation runs client-side in TypeScript with zero round-trips, paired with an interactive Three.js 3D viewport and parametric EMT cut-list generator:

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.