<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Marlowe CAD Engineering]]></title><description><![CDATA[Marlowe CAD Engineering]]></description><link>https://felixmarlowe.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 23:28:53 GMT</lastBuildDate><atom:link href="https://felixmarlowe.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Building a Deterministic IFC 1007.1.1 Half-Diagonal Exit-Separation & Aisle-Graph Validator in TypeScript]]></title><description><![CDATA[When we set out to build a browser-native fire-code floor plan CAD tool (EgressCAD), our core architectural requirement was strict determinism: zero cloud…]]></description><link>https://felixmarlowe.hashnode.dev/building-a-deterministic-ifc-1007-1-1-half-diagonal-exit-separation-aisle-graph-validator-in-typescript</link><guid isPermaLink="true">https://felixmarlowe.hashnode.dev/building-a-deterministic-ifc-1007-1-1-half-diagonal-exit-separation-aisle-graph-validator-in-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Felix Marlowe]]></dc:creator><pubDate>Fri, 04 Dec 2026 08:13:08 GMT</pubDate><content:encoded><![CDATA[<p>When we set out to build a browser-native fire-code floor plan CAD tool (<a href="https://www.egresscad.com/calculators/exit-separation?utm_source=hashnode&amp;utm_medium=editorial&amp;utm_campaign=wave8_exit_sep_ts">EgressCAD</a>), our core architectural requirement was strict determinism: zero cloud CAD servers, zero heuristic LLM guessing on life-safety code rules, and instant sub-millisecond re-evaluation on every table drag at 60 FPS.</p>
<p>One of the most deceptively interesting computational geometry problems in the International Fire Code (IFC) is <strong>Section 1007.1.1 (Two Exits or Exit Access Doorways: Remoteness)</strong>, paired with <strong>chair-back obstacle clearance</strong> and <strong>NFPA 10 travel-distance coverage</strong>. Here is how we implemented those checks in pure, dependency-free TypeScript.</p>
<h2>1. Exact IFC 1007.1.1 Diagonal Remoteness Math</h2>
<p>When a room, ballroom, or enclosed tent requires two or more exits (any assembly space with 50+ occupants under IFC Table 1006.2.1), the exits must be separated by a straight-line distance of at least:</p>
<ul>
<li><strong>1/2 of the maximum overall diagonal dimension</strong> of the building or area served (non-sprinklered buildings and virtually all event tents), or</li>
<li><strong>1/3 of the maximum overall diagonal dimension</strong> when the building is equipped throughout with an automatic NFPA 13 sprinkler system.</li>
</ul>
<p>For a rectangular or polygonal floor perimeter <code>P</code> with vertices <code>V = [(x_0, y_0), ..., (x_{n-1}, y_{n-1})]</code>, the maximum overall diagonal is the diameter of the polygon's convex hull (which for axis-aligned rectangles reduces to <code>Math.hypot(widthFt, depthFt)</code>, and for arbitrary L-shaped ballrooms is computed in <code>O(V^2)</code> across boundary vertices):</p>
<pre><code class="language-ts">export interface Point2D {
  x: number; // feet
  y: number; // feet
}

export interface ExitDoor {
  id: string;
  label: string;
  center: Point2D;
  clearWidthIn: number;
}

export interface ExitSeparationAudit {
  diagonalFt: number;
  factor: 0.5 | 0.3333333333333333;
  requiredMinSeparationFt: number;
  maxPairSeparationFt: number;
  closestPrimaryPairFt: number | null;
  passed: boolean;
  failingPairs: Array&lt;{ a: string; b: string; distanceFt: number }&gt;;
}

export function polygonMaxDiagonalFt(vertices: Point2D[]): number {
  let maxDistSq = 0;
  for (let i = 0; i &lt; vertices.length; i++) {
    for (let j = i + 1; j &lt; vertices.length; j++) {
      const dx = vertices[i].x - vertices[j].x;
      const dy = vertices[i].y - vertices[j].y;
      const dSq = dx * dx + dy * dy;
      if (dSq &gt; maxDistSq) maxDistSq = dSq;
    }
  }
  return Math.sqrt(maxDistSq);
}

export function auditExitSeparation(
  perimeterFt: Point2D[],
  exits: ExitDoor[],
  isFullySprinklered: boolean
): ExitSeparationAudit {
  const diagonalFt = polygonMaxDiagonalFt(perimeterFt);
  const factor = isFullySprinklered ? (1 / 3) : 0.5;
  const requiredMinSeparationFt = diagonalFt * factor;

  if (exits.length &lt; 2) {
    return {
      diagonalFt,
      factor,
      requiredMinSeparationFt,
      maxPairSeparationFt: 0,
      closestPrimaryPairFt: null,
      passed: false,
      failingPairs: [],
    };
  }

  let maxPairSeparationFt = 0;
  const failingPairs: Array&lt;{ a: string; b: string; distanceFt: number }&gt; = [];

  for (let i = 0; i &lt; exits.length; i++) {
    for (let j = i + 1; j &lt; exits.length; j++) {
      const d = Math.hypot(
        exits[i].center.x - exits[j].center.x,
        exits[i].center.y - exits[j].center.y
      );
      if (d &gt; maxPairSeparationFt) maxPairSeparationFt = d;
      if (d + 1e-6 &lt; requiredMinSeparationFt) {
        failingPairs.push({ a: exits[i].label, b: exits[j].label, distanceFt: d });
      }
    }
  }

  // IFC 1007.1.1: At least TWO required exits must satisfy the remoteness separation.
  // (When 3+ exits exist, IFC 1007.1.2 requires the first two to meet 1/2 or 1/3 diagonal,
  // and additional exits to be arranged so one blocked exit doesn't knock out the rest.)
  const passed = maxPairSeparationFt + 1e-6 &gt;= requiredMinSeparationFt;

  return {
    diagonalFt,
    factor,
    requiredMinSeparationFt,
    maxPairSeparationFt,
    closestPrimaryPairFt: failingPairs.length ? Math.min(...failingPairs.map((p) =&gt; p.distanceFt)) : maxPairSeparationFt,
    passed,
    failingPairs,
  };
}
</code></pre>
<h2>2. Real-Time Chair-Back Clear Aisle Distance (Circle vs. OBB)</h2>
<p>Checking 36-inch / 44-inch clear aisles between tables requires modeling <strong>occupied seating envelopes</strong>, not bare furniture footprints. A 60-inch round table (<code>radius = 2.5 ft</code>) gets inflated by <code>1.5 ft</code> (<code>18 inches</code> chair pullout) to an occupied collision radius of <code>4.0 ft</code>.</p>
<p>Between any two circular banquet tables <code>A</code> and <code>B</code>, the true chair-back clear aisle is simply:</p>
<pre><code class="language-ts">const clearAisleIn = (Math.hypot(a.x - b.x, a.y - b.y) - a.occupiedRadiusFt - b.occupiedRadiusFt) * 12;
</code></pre>
<p>For rectangular banquet tables (<code>8' × 30"</code>), stages, and dance floors, we transform the circle center into the rectangle's local rotated frame (Oriented Bounding Box), clamp <code>(lx, ly)</code> to <code>[-halfW, +halfW] × [-halfH, +halfH]</code>, and subtract the occupied seat clearance. Because an average gala ballroom has 20 to 80 tables, pairwise checking (<code>N(N-1)/2 &lt;= 3,160</code> pairs) executes in <strong>&lt; 0.3 milliseconds</strong> in V8 with zero spatial-index overhead.</p>
<h2>3. Rendering Vector Dimension Callouts Directly to SVG &amp; PDF</h2>
<p>Because the exact same pure TypeScript geometry objects feed both our interactive Svelte <code>&lt;svg&gt;</code> canvas AND our server-side <code>pdf-lib</code> + AutoCAD R12 DXF exporters, there is zero drift between what the user sees in the browser and what prints on Sheet A1.1 for the Fire Marshal:</p>
<ul>
<li>Every pair of exits draws a dashed dimension line showing <code>actualFt</code> vs <code>requiredMinSeparationFt</code> (switching cleanly between safety red <code>#C8281D</code> on failure and compliant green <code>#0F7B4E</code> on pass).</li>
<li>Every clear aisle violation highlights the exact pinch point in inches (<code>24" &lt; 36" MIN</code>) so the user nudges a table by 12 inches and watches the violation vanish live.</li>
</ul>
<p>You can test the live exit-separation calculator and geometry engine directly at <strong><a href="https://www.egresscad.com/calculators/exit-separation?utm_source=hashnode&amp;utm_medium=editorial&amp;utm_campaign=wave8_exit_sep_ts">EgressCAD's IFC Exit Separation Calculator</a></strong>.</p>
]]></content:encoded></item><item><title><![CDATA[1D Bin-Packing for 10-Foot 1" EMT Conduit: Exact 1/16" Slip-Fitting Deductions and Saw Kerf Math in TypeScript]]></title><description><![CDATA[Most DIY steel enclosures built from 1-inch Electrical Metallic Tubing (EMT) fail by 1.5 to 3 inches on the first dry-fit. Not because the builder misread…]]></description><link>https://felixmarlowe.hashnode.dev/1d-bin-packing-for-10-foot-1-emt-conduit-exact-1-16-slip-fitting-deductions-and-saw-kerf-math-in-typescript</link><guid isPermaLink="true">https://felixmarlowe.hashnode.dev/1d-bin-packing-for-10-foot-1-emt-conduit-exact-1-16-slip-fitting-deductions-and-saw-kerf-math-in-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[programming]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Felix Marlowe]]></dc:creator><pubDate>Fri, 04 Dec 2026 08:11:39 GMT</pubDate><content:encoded><![CDATA[<p>Most DIY steel enclosures built from 1-inch Electrical Metallic Tubing (EMT) fail by 1.5 to 3 inches on the first dry-fit. Not because the builder misread a tape measure, but because steel structural slip-fittings (3-way corners, flat tees, and center couplers) have internal stop flanges that displace conduit length: and builders forget to deduct them before making cuts from standard 120-inch (10-foot) hardware store sticks.</p>
<p>When we built the deterministic enclosure CAD engine for <a href="https://www.simbaycad.com/guides/golf-simulator-enclosure-cut-list?utm_source=hashnode&amp;utm_medium=editorial&amp;utm_campaign=wave8_emt_binpack">SimBayCAD</a>, we needed a pure TypeScript module that takes arbitrary room dimensions (<code>width</code>, <code>depth</code>, <code>height</code>), computes every frame member with exact slip-fitting seat deductions rounded to the nearest <code>1/16"</code>, and solves the <strong>1D cutting-stock / bin-packing problem</strong> against real <code>120.0"</code> sticks with <code>1/8"</code> (<code>0.125"</code>) chop-saw kerf loss.</p>
<p>Here is how the geometry deduction and First-Fit Decreasing (FFD) bin-packer work under the hood.</p>
<h2>1. Exact Physical Dimensions of 1" EMT &amp; Steel Slip-Fittings</h2>
<p>Despite being sold as "1-inch EMT," trade-size conduit follows ANSI C80.3:</p>
<pre><code class="language-ts">export const EMT_SPECS = {
  tradeSizeIn: 1.0,
  outerDiameterIn: 1.163,
  stockLengthIn: 120.0, // Standard 10-ft Home Depot / Lowe's stick
  kerfLossIn: 0.125,    // 1/8" abrasive chop saw or band saw kerf
  // Corner / Tee socket stop offset: distance from outer fitting face to internal pipe seat
  cornerDeductionPerEndIn: 1.5,
  teeCenterDeductionPerEndIn: 1.375,
} as const;
</code></pre>
<p>For a single structural member connecting two 3-way corner fittings across a target outside-to-outside frame span <code>S</code>, the real cut length is:</p>
<pre><code class="language-ts">function computeCutLength(
  outsideSpanIn: number,
  leftFittingDeductionIn: number,
  rightFittingDeductionIn: number
): number {
  const raw = outsideSpanIn - leftFittingDeductionIn - rightFittingDeductionIn;
  // Round to nearest 1/16" for real tape-measure readability
  return Math.round(raw * 16) / 16;
}
</code></pre>
<h3>Handling Spans Longer Than 120 Inches (Center Split + Coupler)</h3>
<p>A 10-foot wide screen (<code>120"</code> interior opening, ~`128"<code>outside frame width) exceeds a single 10-foot conduit stick. Instead of splicing an awkward 8-inch stub at one corner (which bows under impact-screen tension), the solver splits any span exceeding</code>116"` cleanly at the midpoint through a 4-way center tee (which also anchors the overhead anti-sag depth rib):</p>
<pre><code class="language-ts">export interface CutPiece {
  id: string;
  label: string;
  cutLengthIn: number;
  targetSpanIn: number;
  deductionIn: number;
}

export function buildCrossbarPieces(frameWidthIn: number, side: 'Front' | 'Rear'): CutPiece[] {
  const maxSinglePiece = EMT_SPECS.stockLengthIn - 2; // leave clean margin
  const fullCut = computeCutLength(
    frameWidthIn,
    EMT_SPECS.cornerDeductionPerEndIn,
    EMT_SPECS.cornerDeductionPerEndIn
  );

  if (fullCut &lt;= maxSinglePiece) {
    return [{
      id: `${side.toLowerCase()}-top`,
      label: `${side} Top Crossbar`,
      cutLengthIn: fullCut,
      targetSpanIn: frameWidthIn,
      deductionIn: EMT_SPECS.cornerDeductionPerEndIn * 2,
    }];
  }

  const halfSpan = frameWidthIn / 2;
  const halfCut = computeCutLength(
    halfSpan,
    EMT_SPECS.cornerDeductionPerEndIn,
    EMT_SPECS.teeCenterDeductionPerEndIn
  );

  return [
    {
      id: `${side.toLowerCase()}-top-l`,
      label: `${side} Top Crossbar (Left Half)`,
      cutLengthIn: halfCut,
      targetSpanIn: halfSpan,
      deductionIn: EMT_SPECS.cornerDeductionPerEndIn + EMT_SPECS.teeCenterDeductionPerEndIn,
    },
    {
      id: `${side.toLowerCase()}-top-r`,
      label: `${side} Top Crossbar (Right Half)`,
      cutLengthIn: halfCut,
      targetSpanIn: halfSpan,
      deductionIn: EMT_SPECS.cornerDeductionPerEndIn + EMT_SPECS.teeCenterDeductionPerEndIn,
    },
  ];
}
</code></pre>
<h2>2. Kerf-Aware First-Fit Decreasing (FFD) 1D Bin-Packing</h2>
<p>Once we have the full array of 13 to 15 frame members (4 uprights, 4 depth runners, 2–4 top crossbars, and 1 center anti-sag depth rib), we pack them onto <code>120.0"</code> sticks.</p>
<p>Crucial real-world detail: <strong>every cut after the first piece on a stick consumes one blade kerf (<code>0.125"</code>)</strong>: and even a piece shorter than <code>120"</code> consumes one kerf when trimmed from the factory stick, whereas an exact <code>120.0"</code> uncut piece consumes zero kerf.</p>
<pre><code class="language-ts">export interface StickPlan {
  stickNumber: number;
  pieces: CutPiece[];
  usedIn: number;
  kerfIn: number;
  offcutIn: number;
}

export function packConduitSticks(
  pieces: CutPiece[],
  stockLengthIn = EMT_SPECS.stockLengthIn,
  kerfIn = EMT_SPECS.kerfLossIn
): StickPlan[] {
  // Sort longest cuts first (First-Fit Decreasing)
  const sorted = [...pieces].sort((a, b) =&gt; b.cutLengthIn - a.cutLengthIn);
  const sticks: StickPlan[] = [];

  for (const piece of sorted) {
    if (piece.cutLengthIn &gt; stockLengthIn) {
      throw new Error(`Piece ${piece.label} (${piece.cutLengthIn}") exceeds ${stockLengthIn}" stock.`);
    }

    let placed = false;
    for (const stick of sticks) {
      // Adding another cut to an existing stick requires the piece length + 1 saw kerf
      const needed = piece.cutLengthIn + kerfIn;
      if (stick.offcutIn &gt;= needed - 1e-6) {
        stick.pieces.push(piece);
        stick.usedIn = round16(stick.usedIn + piece.cutLengthIn);
        stick.kerfIn = round16(stick.kerfIn + kerfIn);
        stick.offcutIn = round16(stockLengthIn - stick.usedIn - stick.kerfIn);
        placed = true;
        break;
      }
    }

    if (!placed) {
      const initialKerf = piece.cutLengthIn &lt; stockLengthIn ? kerfIn : 0;
      sticks.push({
        stickNumber: sticks.length + 1,
        pieces: [piece],
        usedIn: round16(piece.cutLengthIn),
        kerfIn: round16(initialKerf),
        offcutIn: round16(stockLengthIn - piece.cutLengthIn - initialKerf),
      });
    }
  }

  return sticks;
}

function round16(v: number): number {
  return Math.round(v * 16) / 16;
}
</code></pre>
<h2>3. Formatting Fractional Inches Cleanly for the Shop Floor</h2>
<p>Nobody wants to read <code>63.6875"</code> off a printout while holding a hacksaw. Converting floating-point inches into reduced mixed fractions (<code>63 11/16"</code>) takes a 10-line Euclidean GCD helper:</p>
<pre><code class="language-ts">export function formatSixteenths(inches: number): string {
  const totalSixteenths = Math.round(inches * 16);
  const whole = Math.floor(totalSixteenths / 16);
  let num = totalSixteenths % 16;
  if (num === 0) return `${whole}"`;
  let den = 16;
  while (num % 2 === 0 &amp;&amp; den % 2 === 0) {
    num /= 2;
    den /= 2;
  }
  return `${whole} ${num}/${den}"`;
}
</code></pre>
<h2>Why Deterministic Solvers Beat Spreadsheets Here</h2>
<p>On a standard 12' × 16' garage bay with a 136" × 106" × 60" frame, naive division (<code>totalLinearInches / 120</code>) tells you to buy 8 sticks: leaving you one stick short at 9 PM on a Saturday because 99" uprights and 65" split crossbars cannot share a 120" tube. FFD bin-packing immediately calculates the real count (<strong>9 sticks</strong>), shows exactly which 54" depth runner pairs cleanly with which 65" crossbar half on Stick #5, and keeps scrap offcuts under 11%.</p>
<p>You can test the live 3D enclosure solver and inspect the cut-schedule math directly in the browser at <strong><a href="https://www.simbaycad.com/guides/golf-simulator-enclosure-cut-list?utm_source=hashnode&amp;utm_medium=editorial&amp;utm_campaign=wave8_emt_binpack">SimBayCAD's 1" EMT Cut List Guide</a></strong>.</p>
]]></content:encoded></item><item><title><![CDATA[Why General Vector Editors Cannot Catch IFC 1007.1.1 Exit Separation Failures (And How We Built a Live Browser Solver)]]></title><description><![CDATA[When we interviewed event planners and tent rental operators about Fire Marshal permit rejections, one failure showed up more than almost any other: IFC…]]></description><link>https://felixmarlowe.hashnode.dev/why-general-vector-editors-cannot-catch-ifc-1007-1-1-exit-separation-failures-and-how-we-built-a-live-browser-solver</link><guid isPermaLink="true">https://felixmarlowe.hashnode.dev/why-general-vector-editors-cannot-catch-ifc-1007-1-1-exit-separation-failures-and-how-we-built-a-live-browser-solver</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[webdev]]></category><category><![CDATA[architecture]]></category><category><![CDATA[cad]]></category><dc:creator><![CDATA[Felix Marlowe]]></dc:creator><pubDate>Thu, 03 Dec 2026 13:19:08 GMT</pubDate><content:encoded><![CDATA[<p>When we interviewed event planners and tent rental operators about Fire Marshal permit rejections, one failure showed up more than almost any other: <strong>IFC Section 1007.1.1 (Remoteness of Exits)</strong>.</p>
<p>A coordinator opens SmartDraw, Visio, or Illustrator, draws a clean 40' x 60' enclosed banquet tent, drops two 72-inch exits on the long side facing the parking lot, exports a PDF, and submits it to the city. Ten business days later, the plan comes back rejected.</p>
<p>Why? Because in an unsprinklered assembly tent, two exits must be separated by at least <strong>half the maximum overall diagonal dimension</strong> of the space:</p>
<pre><code class="language-ts">export function computeDiagonalFeet(widthFt: number, lengthFt: number): number {
  return Math.hypot(widthFt, lengthFt);
}

export function requiredExitSeparationFt(
  widthFt: number,
  lengthFt: number,
  sprinklered: boolean
): number {
  const diag = computeDiagonalFeet(widthFt, lengthFt);
  // IFC 1007.1.1: 1/3 diagonal if equipped throughout with an automatic sprinkler system, else 1/2
  return diag * (sprinklered ? 1 / 3 : 0.5);
}
</code></pre>
<p>For a <code>40' x 60'</code> enclosed tent (<code>diagonal = 72.11 ft</code>), any pair of exits closer than <strong><code>36.06 ft</code></strong> straight-line distance is a hard code violation. General vector drawing tools have no domain model for walls, doors, sprinkler flags, or fire-code predicates, so they happily export invalid diagrams.</p>
<h2>Deterministic Geometry Over Canvas Dragging</h2>
<p>To eliminate redline cycles without forcing event crews into desktop AutoCAD or annual SmartDraw/Visio contracts, we built a pure TypeScript compliance engine inside <strong>EgressCAD</strong> that runs on every pointer move at 60 fps:</p>
<ol>
<li><strong>Perimeter-Anchored Exit Coordinates:</strong> Exits are constrained to the structural envelope (<code>top</code>, <code>bottom</code>, <code>left</code>, <code>right</code>) with exact center offsets in feet, allowing deterministic Euclidean pairwise distance checks against <code>requiredExitSeparationFt()</code>.</li>
<li><strong>Table-to-Table &amp; Wall Aisle Pinch Detection:</strong> Instead of ignoring chair pull-out envelopes, every round banquet table adds a standardized 18-inch occupied chair-back buffer around its diameter. An O(N^2) bounding-circle / OBB clearance sweep flags any aisle pinch narrower than 36 inches (or 44 inches on primary egress corridors) with the exact measured clear width in inches.</li>
<li><strong>Worst-Case Travel Distance &amp; 75-ft NFPA 10 Extinguisher Coverage:</strong> We evaluate Manhattan/Euclidean path distance from the farthest occupied corner to the nearest valid exit (<code>100 ft</code> tent max, <code>200 ft</code> unsprinklered indoor, <code>250 ft</code> sprinklered indoor) and draw true-scale 75-foot extinguisher coverage circles around every <code>2A:10BC</code> icon.</li>
<li><strong>Byte-Identical Server PDF + AutoCAD R2000 <code>.DXF</code>:</strong> Rather than relying on <code>window.print()</code>, the same canonical floor-plan geometry serializes into deterministic 72-DPI vector PDF streams (<code>11x17</code> architectural sheets) and a 7-layer ASCII <code>.DXF</code> for CAD/AHJ reviewers.</li>
</ol>
<p>Try the interactive Quick Egress Checker and read the full breakdown comparing general diagramming tools vs automated IFC CAD: <a href="https://www.egresscad.com/guides/smartdraw-visio-alternative-event-floor-plan?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=wave7_smartdraw">SmartDraw &amp; Visio Alternative for Scaled Event &amp; Tent Fire Marshal Floor Plans</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Modeling Short-Throw Projector Vertical Lens Offset and 16:10 vs 16:9 Clipping in TypeScript and Three.js]]></title><description><![CDATA[When homeowners build an indoor garage golf simulator, projector math fails far more often on vertical lens offset and golfer shadow intersection than on…]]></description><link>https://felixmarlowe.hashnode.dev/modeling-short-throw-projector-vertical-lens-offset-and-16-10-vs-16-9-clipping-in-typescript-and-three-js</link><guid isPermaLink="true">https://felixmarlowe.hashnode.dev/modeling-short-throw-projector-vertical-lens-offset-and-16-10-vs-16-9-clipping-in-typescript-and-three-js</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[ThreeJS]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Felix Marlowe]]></dc:creator><pubDate>Wed, 02 Dec 2026 15:29:34 GMT</pubDate><content:encoded><![CDATA[<p>When homeowners build an indoor garage golf simulator, projector math fails far more often on <strong>vertical lens offset</strong> and <strong>golfer shadow intersection</strong> than on simple throw ratio.</p>
<p>Most online throw calculators treat a projector as a 1D line segment: multiply screen width by throw ratio, get mount distance, done. In a 9-foot or 9.5-foot residential garage with an 8-foot impact screen and an overhead garage door track, a 1D calculator hides two failure modes that ruin installations:</p>
<ol>
<li><strong>Offset-to-ceiling collision:</strong> The lens center must sit above the top edge of the projected image by a fixed percentage of image height, or the owner is forced into heavy digital keystone correction that destroys resolution.</li>
<li><strong>Backswing and head shadow clipping:</strong> A longer short-throw zoom lens (<code>0.69</code> to <code>0.83</code>) mounts close enough to the tee that a 6-foot golfer intercepts the lower ray plane of the frustum.</li>
</ol>
<p>In <a href="https://www.simbaycad.com/guides/optoma-zw350st-vs-benq-tk710sti-golf-simulator">SimBayCAD</a>, we model every projector in a 36-unit datasheet database as a true 3D frustum inside Three.js and run pure-TypeScript ray-plane intersection tests on every dimension change.</p>
<h2>1. Comparing Two Real Short-Throw Lasers: Optoma ZW350ST vs BenQ TK710STi</h2>
<p>Using exact optical specs from <code>hardware-db.ts</code>:</p>
<pre><code class="language-ts">const OPTOMA_ZW350ST = {
  nativeResolution: '1920x1200',
  nativeAspect: '16:10',
  minThrowRatio: 0.521,
  maxThrowRatio: 0.521,
  ansiLumens: 3600,
  verticalOffsetPct: 115,
};

const BENQ_TK710STI = {
  nativeResolution: '3840x2160',
  nativeAspect: '16:9',
  minThrowRatio: 0.69,
  maxThrowRatio: 0.83,
  ansiLumens: 3200,
  verticalOffsetPct: 102.5,
};
</code></pre>
<p>On a standard <strong>10-foot wide (120-inch) impact screen</strong>, look at how differently those two lenses behave in 3D space:</p>
<ul>
<li><p><strong>Throw distance (X/Z mount position):</strong></p>
<ul>
<li><code>Optoma ZW350ST</code> (<code>0.521</code> fixed): <code>120 * 0.521 = 62.5 in</code> (<strong>5.21 ft</strong> from the screen). With the hitting strip at 8.5 to 9.5 ft, the lens sits over 3 feet in front of the player, keeping the entire light cone well clear of head and driver shadows.</li>
<li><code>BenQ TK710STi</code> (<code>0.69</code> to <code>0.83</code> zoom): <code>82.8 in</code> to <code>99.6 in</code> (<strong>6.90 to 8.30 ft</strong>). Near the long end of the zoom range, the lens sits directly above the golfer, requiring careful zoom tightening and ceiling clearance checks.</li>
</ul>
</li>
<li><p><strong>Vertical offset math (ceiling-inverted mount):</strong>
When ceiling-mounted inverted, <code>verticalOffsetPct</code> above <code>100%</code> measures how far above the top image edge the optical axis must sit:</p>
<pre><code class="language-ts">const offsetAboveTopEdgeIn =
  ((projector.verticalOffsetPct - 100) / 100) * projectedImageHeightIn;
const requiredLensHeightIn = screenTopEdgeYIn + offsetAboveTopEdgeIn;
</code></pre>
<ul>
<li>On a 75-inch tall 16:10 image, the Optoma ZW350ST's <strong>115% offset</strong> places the optical axis <strong>11.25 inches above the top of the image</strong>. In a tight 108-inch (9-foot) garage with an 8-foot screen, that forces either a lower image top edge or checking mount bracket thickness down to the half-inch.</li>
<li>The BenQ TK710STi's <strong>102.5% offset</strong> places the optical axis just <strong>1.7 inches above the top of a 67.5-inch 16:9 image</strong>, making flush low-ceiling mounts far simpler.</li>
</ul>
</li>
</ul>
<h2>2. Computing Native Fill vs Custom Resolution Crop</h2>
<p>DIY 1-inch EMT garage enclosures are typically <code>10x8 ft</code> (<code>1.25:1</code>) or <code>12x9 ft</code> (<code>4:3</code>, <code>1.33:1</code>). Computing active illuminated image height from native aspect ratio:</p>
<pre><code class="language-ts">function computeNativeFill(screenWidthIn: number, screenHeightIn: number, aspectRatio: number) {
  const heightLimitedByWidth = screenWidthIn / aspectRatio;
  if (heightLimitedByWidth &lt;= screenHeightIn) {
    return { widthIn: screenWidthIn, heightIn: heightLimitedByWidth, verticalFillPct: (heightLimitedByWidth / screenHeightIn) * 100 };
  }
  const widthLimitedByHeight = screenHeightIn * aspectRatio;
  return { widthIn: widthLimitedByHeight, heightIn: screenHeightIn, verticalFillPct: 100 };
}
</code></pre>
<p>On a 120-inch wide x 96-inch tall enclosure:</p>
<ul>
<li>Native <strong>16:9</strong> (<code>1.778</code>) yields <code>67.5 in</code> (<code>5.62 ft</code>) tall (<strong>70.3%</strong> vertical screen fill unless cropped via custom GPU resolution).</li>
<li>Native <strong>16:10</strong> (<code>1.600</code>) yields <code>75.0 in</code> (<code>6.25 ft</code>) tall (<strong>78.1%</strong> vertical screen fill with zero pixel cropping).</li>
</ul>
<h2>3. Verifying Ray-Plane Shadow Clearance Against Golfer Height</h2>
<p>To compute whether a golfer casts a shadow onto the impact screen, we evaluate the linear ray from the projector lens <code>(0, lensY, throwZ)</code> to the top and bottom screen edges <code>(0, screenBottomY, 0)</code> at the golfer's plane <code>z = golferZ</code>:</p>
<pre><code class="language-ts">const t = (throwZ - golferZ) / throwZ;
const beamBottomAtGolferY = lensY + t * (screenBottomY - lensY);
const headClearanceIn = beamBottomAtGolferY - golferHeightIn;
</code></pre>
<p>Whenever <code>golferZ &lt; throwZ</code> and <code>headClearanceIn &lt; 0</code>, the solver immediately flags a shadow collision in red and highlights the minimum ceiling height or shorter throw lens needed to clear the beam.</p>
<p>You can test the Optoma ZW350ST, BenQ TK710STi, and 34 other short-throw golf simulator projectors in your exact room dimensions free at <a href="https://www.simbaycad.com/guides/optoma-zw350st-vs-benq-tk710sti-golf-simulator">SimBayCAD</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Encoding 50 US Municipal Fire Codes and IFC Tent Thresholds in Pure TypeScript]]></title><description><![CDATA[Event planners and tent rental operators regularly run into a surprising compliance problem when working across state lines: there is no single national…]]></description><link>https://felixmarlowe.hashnode.dev/encoding-50-us-municipal-fire-codes-and-ifc-tent-thresholds-in-pure-typescript</link><guid isPermaLink="true">https://felixmarlowe.hashnode.dev/encoding-50-us-municipal-fire-codes-and-ifc-tent-thresholds-in-pure-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Cloudflare Workers]]></category><category><![CDATA[software architecture]]></category><dc:creator><![CDATA[Felix Marlowe]]></dc:creator><pubDate>Wed, 02 Dec 2026 15:21:57 GMT</pubDate><content:encoded><![CDATA[<p>Event planners and tent rental operators regularly run into a surprising compliance problem when working across state lines: there is no single national square-footage threshold for when a temporary tent or assembly floor plan requires a Fire Marshal permit.</p>
<p>Under the base International Fire Code (IFC Chapter 31), operational permits trigger above <strong>400 sq ft</strong> for enclosed tents with sidewalls and <strong>700 sq ft</strong> for open-sided canopies. Once you model real municipal amendments across the top 50 US event metros, however, the threshold spans a 7.5x range from <strong>120 sq ft</strong> up to <strong>900 sq ft</strong>.</p>
<p>When building <a href="https://www.egresscad.com/permits">EgressCAD</a>, we needed a deterministic, zero-latency rule engine that runs entirely on Cloudflare Workers and in the browser with no external database round-trips per drag event. Here is how we structured our 50-city municipal permit schema and deterministic IFC 2024 / NFPA 101 compliance solver in pure TypeScript.</p>
<h2>1. Normalizing 50 Divergent Local Fire Code Amendments</h2>
<p>Rather than hardcoding city exceptions inside UI components, every jurisdiction is modeled as a strict typed record in <code>municipal_permits.json</code>:</p>
<pre><code class="language-ts">export interface JurisdictionPermitRule {
  slug: string;
  city: string;
  state: string;
  ahjName: string;
  codeEdition: 'IFC_2024' | 'IFC_2021' | 'IFC_2018' | 'NFPA_101';
  codeLabel: string;
  tentPermitSqFtClosed: number;
  tentPermitSqFtOpen: number;
  assemblyPlanOccupantTrigger: number;
  peStampRequiredRule: string;
  peStampFlag: boolean;
  typicalLeadTimeDays: number;
  requiredSubmittalItems: string[];
  localNotes: string;
  officialSourceUrl: string;
}
</code></pre>
<p>Separating <code>tentPermitSqFtClosed</code> and <code>tentPermitSqFtOpen</code> from <code>peStampFlag</code> immediately exposes real regional differences that generic permit calculators miss:</p>
<ul>
<li><strong>120 sq ft strict tier:</strong> Detroit, MI (<code>BSEED &amp; Detroit Fire Marshal Division</code>) and Cleveland, OH (<code>Building &amp; Housing</code>) require temporary structure permits above 120 sq ft.</li>
<li><strong>200 sq ft tier:</strong> Memphis and Shelby County, TN trigger a permit above 200 sq ft for gatherings of 10 or more people.</li>
<li><strong>400 / 700 sq ft IFC baseline:</strong> Austin, Dallas, Fort Worth, Kansas City, Cincinnati, Denver, Nashville, and Seattle follow IFC Chapter 31 thresholds with local fire-break and cooking addenda.</li>
<li><strong>600 to 900 sq ft upper tier:</strong> Milwaukee, WI triggers at <code>&gt;600 sq ft</code>, Pittsburgh, PA at <code>&gt;700 sq ft</code>, St. Louis, MO at <code>&gt;=800 sq ft</code>, and Richmond, VA under the Virginia Statewide Fire Prevention Code at <code>&gt;=900 sq ft</code> (with &gt;50 occupants).</li>
</ul>
<h2>2. Guarding Against False Confidence on PE / Architect Seals</h2>
<p>Software can compute IFC Table 1004.5 occupant loads (<code>15 sq ft net</code> for tables and chairs, <code>7 sq ft net</code> for concentrated seating, <code>5 sq ft net</code> for standing areas), half-diagonal exit separation (IFC 1007.1.1), and 75-foot portable fire extinguisher travel rings (NFPA 10) deterministically.</p>
<p>Software cannot legally replace a state-licensed Registered Architect (RA) or Professional Engineer (PE) where local law requires a stamped seal. That is why <code>peStampFlag: true</code> triggers an explicit banner and submittal warning across our 7 strict stamping jurisdictions (<strong>NYC DOB TPA, Chicago, Miami-Dade HVHZ, Orlando, Tampa, Boston, and Washington, DC</strong>) as well as any structural trigger such as elevated stages over 30 inches or engineered wind-load anchoring.</p>
<p>Even in those 7 metros, exporting an IFC-verified 7-layer AutoCAD R2000 <code>.DXF</code> (<code>A-WALL-TENT</code>, <code>A-FURN-SEAT</code>, <code>E-EGRESS-PATH</code>, <code>F-EXTINGUISHER</code>, <code>A-ANNO-DIMS</code>) lets an engineer verify wind and structural loads without billing hours to redraw banquet rounds from scratch.</p>
<h2>3. Keeping the Solver Pure and 60fps Interactive</h2>
<p>Because the compliance engine (<code>solveComplianceAudit(config, rule)</code>) has zero DOM dependencies and zero network I/O, the exact same TypeScript function executes:</p>
<ol>
<li>At 60fps inside the Svelte 5 browser canvas whenever a planner drags a 60-inch banquet round or widens a 72-inch tent exit.</li>
<li>Inside the static city checker widgets across all 50 <code>/permits/[city]</code> pages.</li>
<li>Inside our Vitest regression suite asserting exact boundary conditions (<code>49</code> vs <code>50</code> occupants flipping required exits from <code>1</code> to <code>2</code>, and <code>43"</code> vs <code>44"</code> clear aisle pinch checks).</li>
</ol>
<p>You can inspect all 50 US municipal Fire Marshal thresholds and test a scaled tent or ballroom layout live in the browser at <a href="https://www.egresscad.com/permits">EgressCAD</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Ray-Tracing Projector Shadows and Garage Door Track Collisions in Pure TypeScript]]></title><description><![CDATA[When someone builds an indoor golf simulator in a residential garage, the three most expensive mistakes are purely geometric: Rather than relying on rough…]]></description><link>https://felixmarlowe.hashnode.dev/ray-tracing-projector-shadows-and-garage-door-track-collisions-in-pure-typescript</link><guid isPermaLink="true">https://felixmarlowe.hashnode.dev/ray-tracing-projector-shadows-and-garage-door-track-collisions-in-pure-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[geometry]]></category><category><![CDATA[Sveltekit]]></category><dc:creator><![CDATA[Felix Marlowe]]></dc:creator><pubDate>Tue, 01 Dec 2026 14:36:31 GMT</pubDate><content:encoded><![CDATA[<p>When someone builds an indoor golf simulator in a residential garage, the three most expensive mistakes are purely geometric:</p>
<ol>
<li>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.</li>
<li>Forgetting that 1-inch trade-size EMT conduit actually has a <strong>1.163-inch outer diameter</strong> (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.</li>
<li>Measuring the ceiling height in the middle of the garage while ignoring a <strong>standard 15-inch drop garage door track</strong> or overhead opener rail hanging right over the driver's follow-through arc.</li>
</ol>
<p>Rather than relying on rough rules of thumb or an LLM guess, we built a deterministic TypeScript optics and biomechanics solver inside <a href="https://www.simbaycad.com/?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=raycast_engine">SimBayCAD</a> (<code>raycast-optics.ts</code> and <code>swing-biomechanics.ts</code>) that runs in under 1 ms on every slider change in the browser.</p>
<p>Here is how the math breaks down.</p>
<h2>1. Exact Viewable Screen Geometry From Trade-Size EMT Pipe</h2>
<p>A "10 ft x 8 ft" DIY enclosure frame built from 1-inch EMT conduit does <strong>not</strong> give you a 120" x 96" projected image. You lose pipe outer diameter plus bungee clearance on every clamped edge:</p>
<pre><code class="language-ts">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 };
}
</code></pre>
<p>At <code>1.163"</code> pipe OD and <code>1.5"</code> bungee gap per side, a <code>120" x 96"</code> outer frame drops to <code>114.67" x 91.84"</code> 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.</p>
<h2>2. Projective 3D Shadow Raycasting Onto the Impact Screen</h2>
<p>Once we solve the projector's lens height <code>lensY</code>, lateral mount coordinate <code>mountX</code>, and longitudinal throw plane <code>mountZ = screenZ + recommendedThrowDistanceIn</code> (balancing optical zoom limits, ceiling bracket clearance, and vertical keystone angle), we project 3D golfer occluder points <code>(gx, gy, gz)</code> onto the impact screen plane <code>z = screenZ</code>:</p>
<pre><code class="language-ts">// Any 3D occluder point (gx, gy, gz) with screenZ &lt; gz &lt; mountZ projects onto z = screenZ at:
//   t  = (mountZ - screenZ) / (mountZ - gz)
//   sx = mountX + (gx - mountX) * t
//   sy = lensY  + (gy - lensY)  * t
</code></pre>
<p>Why sample multiple <code>(gx, gz)</code> points instead of a single center dot?</p>
<ul>
<li>A right-handed golfer's stance center sits roughly <strong>20 inches left of the tee</strong> (<code>teeX - 20</code>), while a left-handed golfer sits <code>teeX + 20</code>.</li>
<li>During address and early follow-through, the lead shoulder and extended arms pass slightly forward of the ball (<code>ballToScreenIn - 14</code>), while the back of the head and torso sit slightly behind it (<code>ballToScreenIn + 14</code>).</li>
<li>Effective golfer head height includes the hitting mat thickness (<code>golferAddressHeightIn = golfer.matThicknessIn + golfer.heightIn * 0.93</code>).</li>
</ul>
<p>For every sampled <code>(gx, gy, gz)</code> between the lens and the screen, if <code>sx</code> falls within the projected image bounds <code>[imgLeft, imgRight]</code>, the projected shadow height <code>sy</code> above the bottom of the screen tells us immediately whether the golfer blocks the image and by how many inches.</p>
<p>When a room's ceiling forces a downward keystone tilt (<code>ceiling_too_low</code> or <code>ceiling_too_high</code>), the solver automatically slides the recommended mount toward the shortest shadow-free edge of the projector's optical zoom window (<code>shadowFreeLimitIn = golfer.ballToScreenIn - 10</code>) before computing <code>verticalKeystoneDeg = atan2(verticalDeficitIn, recommendedThrowDistanceIn) * 180 / PI</code>.</p>
<h2>3. Sloped Ceilings and Overhead Garage Door Track Obstacles</h2>
<p>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.</p>
<p>In <code>swing-biomechanics.ts</code>, we evaluate the true ceiling height at any longitudinal coordinate <code>z</code> along the hitting bay:</p>
<pre><code class="language-ts">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);
}
</code></pre>
<p>Then <code>evaluateOverheadAtSwing()</code> checks whether the golfer's 80-inch longitudinal swing corridor (<code>[ballZ - 40, ballZ + 40]</code>) intersects:</p>
<ul>
<li><code>standard_15in</code> sectional tracks (<code>rawDropIn = Math.max(12, room.garageTrackDropIn || 15)</code>)</li>
<li><code>high_lift</code> tracks (hugging within 4 to 5 inches of the ceiling and terminating further toward the door)</li>
<li><code>roll_up</code> drums (14-inch drop confined to the final 18 inches near the door header)</li>
</ul>
<p>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.</p>
<h2>Try the Interactive Solver</h2>
<p>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:</p>
<ul>
<li><a href="https://www.simbaycad.com/calculators/projector-throw?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=raycast_engine">Interactive Projector Throw &amp; Shadow Calculator</a></li>
<li><a href="https://www.simbaycad.com/?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=raycast_engine">3D Golf Simulator Room Planner (SimBayCAD)</a></li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Generating True-Scale 11x17 Architectural PDFs and AutoCAD R2000 DXF Files on Cloudflare Workers]]></title><description><![CDATA[When we built EgressCAD for event planners, tent rental crews, and venue operators who need municipal Fire Marshal permit submittals, we wanted to avoid…]]></description><link>https://felixmarlowe.hashnode.dev/generating-true-scale-11x17-architectural-pdfs-and-autocad-r2000-dxf-files-on-cloudflare-workers</link><guid isPermaLink="true">https://felixmarlowe.hashnode.dev/generating-true-scale-11x17-architectural-pdfs-and-autocad-r2000-dxf-files-on-cloudflare-workers</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[Cloudflare Workers]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[software architecture]]></category><dc:creator><![CDATA[Felix Marlowe]]></dc:creator><pubDate>Mon, 30 Nov 2026 14:56:57 GMT</pubDate><content:encoded><![CDATA[<p>When we built <a href="https://www.egresscad.com/">EgressCAD</a> for event planners, tent rental crews, and venue operators who need municipal Fire Marshal permit submittals, we wanted to avoid running headless Chrome, LibreCAD, or a heavy native CAD microservice just to export drawings.</p>
<p>Everything runs inside a single SvelteKit app deployed on Cloudflare Workers: a pure-TypeScript IFC/NFPA compliance solver, a true-scale 3-sheet 11"x17" architectural PDF generator using <code>pdf-lib</code>, and a zero-dependency AutoCAD R2000 (<code>AC1015</code>) DXF emitter.</p>
<p>Here is how the coordinate math, CAD layering, and fire-code edition differences work in practice.</p>
<h2>1. Two Coordinate Systems: Browser SVG vs. CAD &amp; PDF</h2>
<p>Interactive floor-plan editors in the browser work naturally in top-left origin coordinates (<code>X</code> increases East, <code>Y</code> increases South/down from the north wall).</p>
<p>Both AutoCAD DXF and PDF (<code>pdf-lib</code>) use bottom-left origin coordinates where <code>Y</code> increases North/up. Getting the flip wrong mirrors exits, heater setbacks, and north arrows silently.</p>
<p>In our DXF exporter, we emit geometry at true <code>1:1</code> scale in <strong>inches</strong>, with origin <code>(0, 0)</code> locked to the southwest corner of the tent or room:</p>
<pre><code class="language-ts">const toCadX = (xFt: number) =&gt; Number((xFt * 12).toFixed(2));
const toCadY = (yFt: number) =&gt; Number(((config.lengthFt - yFt) * 12).toFixed(2));
</code></pre>
<p>Inside the DXF <code>HEADER</code> section, setting <code>$ACADVER</code> to <code>AC1015</code> (AutoCAD R2000), <code>$INSUNITS</code> to <code>1</code> (Inches), and <code>$LUNITS</code> to <code>4</code> (Architectural feet-and-inches) ensures any architect or municipal plans examiner opening the file in AutoCAD, BricsCAD, or QCAD sees real architectural dimensions immediately with zero rescaling:</p>
<pre><code class="language-ts">push(
  0, 'SECTION',
  2, 'HEADER',
  9, '$ACADVER', 1, 'AC1015',
  9, '$INSUNITS', 70, 1, // Inches
  9, '$LUNITS', 70, 4,   // Architectural
  0, 'ENDSEC'
);
</code></pre>
<h2>2. Seven AIA-Style CAD Layers Without an External CAD Kernel</h2>
<p>Fire Marshals and downstream structural engineers expect separated CAD layers so they can toggle furniture off while verifying egress paths or extinguisher coverage. In pure TypeScript, defining the <code>TABLES -&gt; LAYER</code> section takes fewer than 20 lines:</p>
<pre><code class="language-ts">const LAYERS = [
  { name: 'A-WALL-TENT', color: 7 },      // White/Black perimeter walls
  { name: 'A-FURN-SEAT', color: 8 },      // Gray tables, chairs, stages
  { name: 'E-EXIT-SIGN', color: 3 },      // Green exit openings &amp; signs
  { name: 'E-EGRESS-PATH', color: 3 },    // Green egress aisles &amp; chords
  { name: 'F-EXTINGUISHER', color: 1 },   // Red 2A:10BC units &amp; 75' radii
  { name: 'F-HAZARD-SETBACK', color: 1 }, // Red 10' heater/LP-gas zones
  { name: 'A-ANNO-DIMS', color: 5 }       // Blue dimension annotations
];
</code></pre>
<p>Every <code>LINE</code>, <code>CIRCLE</code>, <code>LWPOLYLINE</code>, and <code>TEXT</code> entity simply references its layer name via group code <code>8</code>. We also run every user-entered string through a strict ASCII sanitizer (<code>[^\x20-\x7E]</code> stripped, length capped) because raw newlines or smart quotes inside DXF group code <code>1</code> values corrupt older CAD parsers.</p>
<h2>3. True-Scale 11"x17" Architectural PDFs in <code>pdf-lib</code></h2>
<p>Municipal permit desks almost universally ask for <strong>11"x17" Tabloid Landscape</strong> (<code>1224 x 792 pt</code> at <code>72 pt/in</code>) with a fixed right-hand architectural title block (<code>216 pt</code> wide), graphic scale bar, north arrow, and printed scale ratio (such as <code>1/16" = 1'-0"</code> or <code>1/8" = 1'-0"</code>).</p>
<p>Rather than fitting the tent to arbitrary pixel percentages (which ruins architectural scaling when someone puts a physical scale ruler on printed paper), we snap the viewport scale to standard US architectural fractions:</p>
<ul>
<li><code>1/4" = 1'-0"</code> (<code>18 pt</code> per foot)</li>
<li><code>1/8" = 1'-0"</code> (<code>9 pt</code> per foot)</li>
<li><code>1/16" = 1'-0"</code> (<code>4.5 pt</code> per foot)</li>
<li><code>1/32" = 1'-0"</code> (<code>2.25 pt</code> per foot)</li>
</ul>
<p>We pick the largest standard scale where the full tent + exterior setback margin fits inside the drawable frame, then draw a matching graphic scale bar (<code>0' - 10' - 20' - 40'</code>) using the exact same <code>ptPerFt</code> multiplier. That way, even if an applicant prints "Fit to Page" on 8.5"x11" paper, the graphic scale bar remains proportionally valid.</p>
<p>One subtle gotcha with <code>pdf-lib</code>'s built-in StandardFonts (<code>Helvetica</code>, <code>Courier</code>): they only encode WinAnsi characters. Any Unicode multiplication symbol (<code>×</code>), greater-than-or-equal sign (<code>≥</code>), or curly quote will throw a runtime encoding error unless normalized first:</p>
<pre><code class="language-ts">function asciiSafe(input: string): string {
  return input
    .replace(/[\u2018\u2019]/g, "'")
    .replace(/[\u201C\u201D]/g, '"')
    .replace(/[\u2013\u2014]/g, '-')
    .replace(/\u00D7/g, 'x')
    .replace(/\u2265/g, '&gt;=')
    .replace(/\u2264/g, '&lt;=')
    .replace(/[^\x20-\x7E]/g, ' ');
}
</code></pre>
<h2>4. Handling Fire-Code Edition Drift Deterministically</h2>
<p>Building a fire-code checker is mostly an exercise in not hardcoding a single textbook citation. US municipalities enforce different code cycles simultaneously:</p>
<ul>
<li><strong>IFC 2024</strong> renumbered the temporary tent exit table to <strong>Table 3103.11</strong> (whereas <strong>IFC 2021</strong> and <strong>IFC 2018</strong> cite <strong>Table 3103.12.2</strong>).</li>
<li><strong>NFPA 101</strong> uses <strong>Table 7.3.1.2</strong> for occupant load factors (<code>15</code> sq ft/person tables &amp; chairs, <code>7</code> sq ft chairs only, <code>5</code> sq ft standing), whereas IFC uses <strong>Table 1004.5</strong>.</li>
<li>The <strong>half-diagonal exit separation rule</strong> (IFC Section 1007.1.1) requires two exits to be separated by at least <code>0.5 * sqrt(W^2 + L^2)</code> in non-sprinklered tents and halls, dropping to <code>1/3</code> the diagonal only when full NFPA 13 automatic sprinkler coverage is present.</li>
<li>Winter events trigger <strong>IFC 3107.12</strong> (10-ft clearance from open/indirect tent heaters to fabric) and <strong>IFC 3107.16</strong> (10-ft minimum outdoor clearance for portable LP-gas containers under 500 gallons).</li>
</ul>
<p>Because the entire compliance solver (<code>compliance-solver.ts</code>) is pure TypeScript with zero browser DOM dependencies, the exact same function drives both the live interactive SVG studio in the browser and the server-side PDF/DXF generators on Cloudflare Workers, guaranteeing the numbers on Sheet FP-102 always match what the user verified on screen.</p>
<p>Finally, software cannot replace a licensed engineer where local law requires a seal: our jurisdiction metadata explicitly flags cities like NYC, Chicago, Miami-Dade, Orlando, Tampa, Boston, and Washington DC whenever an architect or PE stamp may be triggered above local size or occupant thresholds.</p>
<p>If you want to inspect the live geometry checks, interactive IFC calculators, or a sample 3-sheet 11x17 PDF packet, you can try the studio directly with no signup at <a href="https://www.egresscad.com/">https://www.egresscad.com/</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Ray-Tracing Projector Shadows and 1-Inch EMT Deductions in Three.js for Home Golf Simulators]]></title><description><![CDATA[How SimBayCAD ray-traces projector shadow intersections in Three.js and solves 1/16-inch 1-inch EMT enclosure cut lists in TypeScript.]]></description><link>https://felixmarlowe.hashnode.dev/ray-tracing-projector-shadows-and-1-inch-emt-deductions-in-three-js-for-home-golf-simulators</link><guid isPermaLink="true">https://felixmarlowe.hashnode.dev/ray-tracing-projector-shadows-and-1-inch-emt-deductions-in-three-js-for-home-golf-simulators</guid><dc:creator><![CDATA[Felix Marlowe]]></dc:creator><pubDate>Fri, 27 Nov 2026 21:33:04 GMT</pubDate><content:encoded><![CDATA[<p>Most DIY home golf simulator builds start with a tape measure in a two-car garage and end with two expensive surprises: a short-throw projector that casts the golfer's head shadow straight onto the impact screen, or an enclosure frame cut from 1-inch EMT conduit that comes out three inches too wide because nobody deducted steel corner slip-fitting insertion depths.</p>
<p>While building <a href="https://www.simbaycad.com/?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=threejs_optics">SimBayCAD</a>, I wanted to move those calculations out of fragile spreadsheets and into an interactive, deterministic Three.js studio that runs directly in the browser with zero signup. Here is how the optical ray-casting, biomechanical swing clearance model, and 1/16-inch EMT cut-list solver work in TypeScript.</p>
<h2>1. Modeling Real Projector Optics (Throw Ratio + Vertical Lens Offset)</h2>
<p>A common misconception when hanging a short-throw golf simulator projector (such as a BenQ AK700ST or Optoma GT2000HDR) is assuming the lens aims straight horizontally at the center of the impact screen. In reality, fixed-offset short-throw lenses project upward (or downward when ceiling-mounted inverted) by a specific percentage of image height.</p>
<p>For each of the 36 projectors in our hardware catalog, we store:</p>
<ul>
<li>Native aspect ratio (<code>16:9</code>, <code>16:10</code>, or <code>4:3</code>) and resolution</li>
<li>Minimum and maximum throw ratio (<code>throwMin</code>, <code>throwMax</code>)</li>
<li>Vertical lens offset percentage (<code>offsetPct</code>)</li>
<li>Ansi lumens and laser/lamp type</li>
</ul>
<p>Given a user's screen width <code>W</code> and height <code>H</code> (fitted inside their EMT enclosure with perimeter bungee clearance), the optical engine solves:</p>
<ol>
<li><strong>Valid throw corridor:</strong> <code>minDist = W * throwMin</code> to <code>maxDist = W * throwMax</code>.</li>
<li><strong>Ceiling mount height and drop-pipe length:</strong> Computed from the top of the projected image plus <code>offsetPct * H</code> so the beam fills the impact screen cleanly without digital keystone distortion (which crops pixels and reduces brightness).</li>
<li><strong>Garage door track clearance:</strong> Compares the projector lens elevation and mounting bracket against standard 12-inch tracks, high-lift 4-inch drop tracks, or wall-mounted jackshaft openers so the garage door never clips the projector mount.</li>
</ol>
<h2>2. Deterministic Golfer Shadow Intersection in 3D</h2>
<p>To flag projector shadows before anyone drills into drywall, the side-optics solver constructs the exact projection frustum from the ceiling mount point <code>(X_p, Y_p, Z_p)</code> to the four corners of the impact screen, then tests ray intersections against a parametric golfer envelope positioned at the hitting strip <code>(X_tee, Y_tee)</code>:</p>
<ul>
<li><strong>Address head height:</strong> Scales with the selected golfer height (<code>5'4"</code> to <code>6'6"</code>), standing on the hitting mat thickness.</li>
<li><strong>Driver swing apex arc:</strong> Computes the backswing and follow-through arc radius for the longest club swung indoors (driver <code>45.5"</code>, fairway wood, or iron), testing both ceiling clearance and rear/side wall impact margins.</li>
</ul>
<p>When the ray from the projector lens to the top or middle of the screen intersects the golfer's head or downswing volume, SimBayCAD highlights the shadow line directly in the Three.js 3D viewport and side-optics elevation view, and recommends moving the mount forward (shorter throw lens) or adjusting tee offset.</p>
<h2>3. Launch Monitor Sensor Zones: Radar vs. Photometric</h2>
<p>Different launch monitors impose completely different room-depth requirements:</p>
<ul>
<li><strong>Behind-ball Doppler radar units</strong> (Garmin Approach R10, FlightScope Mevo+, TrackMan 4) require 6 to 8 feet behind the tee plus 8 to 10+ feet of ball flight to the screen, pushing minimum room depth to 16-20 feet.</li>
<li><strong>Side-mounted photometric units</strong> (Bushnell Launch Pro, GC3, SkyTrak+, Uneekor EYE MINI, Square Golf) read ball spin within inches of impact, allowing compact 10x12 and 12x16 garage builds.</li>
<li><strong>Overhead ceiling-mounted units</strong> (Uneekor EYE XO, ProTee VX, TrackMan iO) require specific mounting zones 3 to 4 feet in front of the tee and clear of the projector beam.</li>
</ul>
<p>SimBayCAD renders the exact radar/camera zone frustum on the floor and ceiling across 18 launch monitors so builders can compare right-handed, left-handed, and dual-handed off-center hitting strips before buying hardware.</p>
<h2>4. Exact 1/16-Inch 1" EMT Cut Schedules and 10-ft Stick Nesting</h2>
<p>Home simulator enclosures are typically framed with standard 1-inch EMT electrical conduit (sold in 10-foot sticks at hardware stores) joined by steel 3-way and 4-way corner slip fittings. Two real-world dimensions break naive cut math:</p>
<ol>
<li><strong>Fitting insertion deductions:</strong> Each steel corner connector adds <code>1.75"</code> to <code>2.25"</code> per joint depending on fitting style. Cutting pipes to outer bay width produces a frame that is up to 4 inches too wide.</li>
<li><strong>10-foot stick nesting:</strong> Most width crossbars span 11 to 14 feet, requiring split spans with coupling sleeves and a center anti-sag depth rib.</li>
</ol>
<p>Our pure-TypeScript BOM solver deducts every fitting depth down to <code>1/16"</code>, splits long spans cleanly across standard 120-inch EMT sticks using a bin-packing nesting pass to minimize scrap conduit, and generates a 4-sheet printable PDF blueprint pack (<code>pdf-lib</code> inside Cloudflare Workers) showing the full cut schedule, stick map, and ceiling mounting coordinates.</p>
<p>You can test your own garage or basement dimensions, compare 36 projectors and 18 launch monitors, and share a build link directly at <a href="https://www.simbaycad.com/?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=threejs_optics">SimBayCAD</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Building a Deterministic Fire-Code CAD Engine in TypeScript and Cloudflare Workers]]></title><description><![CDATA[How EgressCAD runs deterministic IFC/NFPA 101 fire-code checks and generates true-scale 11x17 vector PDFs and AutoCAD R12 DXFs in TypeScript and Cloudflare…]]></description><link>https://felixmarlowe.hashnode.dev/building-a-deterministic-fire-code-cad-engine-in-typescript-and-cloudflare-workers</link><guid isPermaLink="true">https://felixmarlowe.hashnode.dev/building-a-deterministic-fire-code-cad-engine-in-typescript-and-cloudflare-workers</guid><dc:creator><![CDATA[Felix Marlowe]]></dc:creator><pubDate>Fri, 27 Nov 2026 21:32:03 GMT</pubDate><content:encoded><![CDATA[<p>When an event producer or tent rental company pulls an operational fire permit for a 40x60 tent or a 200-guest hotel ballroom gala, the local fire marshal does not accept a rough sketch from Canva or Lucidchart. Inspectors check concrete numbers: occupant load under IFC Table 1004.5, minimum exit count and 72-inch tent exit widths under IFC Table 3103.11, the one-half diagonal exit remoteness rule, 36-inch and 44-inch clear egress aisles around banquet seating, 75-foot Class 2A:10BC fire extinguisher travel radii under NFPA 10, and minimum clearances for indirect-fired tent heaters (IFC 3107.12) and LP-gas tanks (IFC 3107.16).</p>
<p>Most commercial CAD tools either cost hundreds of dollars a month, require desktop installation, or treat life-safety rules as manual drafting notes rather than executable geometry checks. While building <a href="https://www.egresscad.com/?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=cad_workers">EgressCAD</a>, I wanted to see how far a purely deterministic browser + Cloudflare Workers architecture could go: live 2D editing, real-time code auditing, and true architectural-scale 11x17 tabloid PDF + AutoCAD R12 DXF generation with zero external CAD backend.</p>
<p>Here is how the geometry engine, code verifier, and vector exporters work in TypeScript.</p>
<h2>1. Separating Pure Geometry from UI and Storage</h2>
<p>The first architectural decision was keeping every code formula, spatial calculation, and vector export in pure TypeScript modules with zero DOM or Node-native dependencies. That single constraint pays off in three ways:</p>
<ol>
<li><strong>Instant client-side feedback:</strong> Dragging a 60-inch round table or shifting an exit door along a tent perimeter re-runs all nine IFC/NFPA compliance checks on every frame with zero round-trips.</li>
<li><strong>Identical server verification:</strong> The exact same TypeScript module runs inside the Cloudflare Worker when generating the final 3-sheet 11x17 PDF packet and layered DXF file, so what the user audits on screen is guaranteed to match the printed submittal byte for byte.</li>
<li><strong>Deterministic unit tests:</strong> Every life-safety rule (including edge cases like the 1/3 diagonal sprinkler exception or LP-gas rack separation) can be tested directly against real municipal thresholds in milliseconds.</li>
</ol>
<h2>2. Modeling IFC and NFPA Rules as Spatial Predicates</h2>
<p>Instead of treating a floor plan as loose shapes, EgressCAD stores typed spatial entities in feet from a <code>(0, 0)</code> origin: structure bounds (enclosed tent, open canopy, indoor ballroom, outdoor fenced site), exit openings along perimeter edges, round/rectangular tables with explicit 18-inch chair pull-out rings, stages, bars, dance floors, portable extinguishers, indirect tent heaters, LP-gas cylinders, and generators.</p>
<p>From that scene graph, the deterministic audit computes nine checks:</p>
<ul>
<li><strong>Governing Occupant Load (IFC Table 1004.5):</strong> Computes area-based load (<code>floorArea / loadFactor</code>, using 15 sq ft/person for tables and chairs, 7 sq ft/person for concentrated seating, or 5 sq ft/person for standing space) and compares it against actual placed seat count, taking the governing maximum.</li>
<li><strong>Exit Count and Aggregate Width (IFC Table 3103.11 &amp; 1005.3.2):</strong> Verifies minimum exits by occupant bracket (e.g., 2 exits for 50-199 occupants in a tent, 3 exits for 200-499, 4 exits for 500-999), enforces the 72-inch minimum clear width for tent exits (36 inches for indoor doors), and checks total capacity at 0.2 inches per occupant.</li>
<li><strong>Exit Remoteness (IFC 1007.1.1):</strong> Computes the Euclidean diagonal of the assembly area (<code>sqrt(W^2 + L^2)</code>) and verifies the minimum pairwise separation between primary exits meets <code>0.5 * diagonal</code> (or <code>0.33 * diagonal</code> when the venue is fully sprinklered).</li>
<li><strong>Clear Aisle Widths:</strong> Expands each banquet table radius by the 18-inch occupied chair pull-out envelope and verifies clearance between adjacent occupied rings and perimeter walls meets the 36-inch secondary and 44-inch main egress path minimums.</li>
<li><strong>NFPA 10 Extinguisher Coverage:</strong> Checks that every corner and interior grid sample of the structure lies within 75 feet of at least one 2A:10BC extinguisher, rendering dashed 75-ft coverage circles directly on the canvas and Sheet FP-101.</li>
<li><strong>Winter Heating &amp; LP-Gas Clearances (IFC 3107.12 &amp; 3107.16):</strong> When indirect heaters, propane tanks, or generators are placed outside a winter tent, checks the minimum 10-foot setback for heating equipment and 10-to-20-foot separation for LP-gas containers, and writes explicit code notes onto the submittal schedules.</li>
</ul>
<h2>3. True-Scale 11x17 Tabloid PDFs Without a Headless Browser</h2>
<p>A common shortcut for web-to-PDF export is rasterizing an HTML canvas or spawning Puppeteer. Both break down on fire marshal submittals: raster images blur when inspectors zoom into dimensions, and headless Chrome cannot run inside a lightweight edge Worker.</p>
<p>Instead, we generate vector PDFs directly in TypeScript using <code>pdf-lib</code> on true ANSI B (<code>11" x 17"</code>, or <code>1224 x 792 pt</code>) landscape sheets:</p>
<ul>
<li><strong>Sheet FP-101 (Scaled Floor Plan):</strong> Selects an exact architectural scale (<code>1/16" = 1'-0"</code> or <code>1/8" = 1'-0"</code> depending on venue footprint), maps feet directly to PDF points (<code>1 ft = 4.5 pt</code> at <code>1/16"</code> scale), draws crisp vector walls, exit arrows, dashed chair-pull-out rings, 75-ft extinguisher circles, graphic scale bar, north arrow, NFPA 170 legend, and a right-hand title block with jurisdiction, code edition, and <code>PASS (9/9)</code> audit status.</li>
<li><strong>Sheet FP-102 (Code &amp; Egress Calculation Schedule):</strong> Tabulates every IFC/NFPA formula, input, required value, provided value, and pass/fail badge so the plan reviewer can verify the math in 30 seconds.</li>
<li><strong>Sheet FP-103 (Site &amp; Fire Access Plan):</strong> Shows exterior fire-lane access, 10-ft/20-ft heater and LP-gas clearances, and generator setbacks.</li>
</ul>
<p>For free previews, the same generator overlays a tiled diagonal <code>DRAFT - NOT FOR PERMIT SUBMITTAL</code> watermark across all three sheets and streams the PDF straight into an in-page preview modal via Blob URLs (avoiding mobile and desktop popup blockers). Paid packets strip the watermark and generate an accompanying AutoCAD R12 <code>.dxf</code> file using clean ASCII <code>ENTITIES</code> sections (<code>LINE</code>, <code>CIRCLE</code>, <code>LWPOLYLINE</code>, <code>TEXT</code>) organized onto standard layers (<code>A-WALL</code>, <code>E-EXIT</code>, <code>F-EXTG</code>, <code>I-FURN</code>, <code>A-ANNO</code>) so architects or venue engineers can open it in AutoCAD, BricsCAD, or QCAD with zero translation cleanup.</p>
<h2>4. Handling Local Municipal Guardrails Honestly</h2>
<p>One hard lesson in building compliance software is knowing where deterministic software stops and licensed professionals begin. Fire code thresholds vary sharply across US cities: Houston triggers tent permits above 1,200 sq ft, Austin and Los Angeles follow 400 sq ft enclosed / 700 sq ft open canopy rules, while Miami-Dade triggers permits at 120 sq ft under High-Velocity Hurricane Zone (HVHZ) wind rules.</p>
<p>More importantly, seven major US jurisdictions (New York City, Chicago, Miami-Dade, Orlando, Tampa, Boston, and Washington, DC) require a licensed Professional Engineer (PE) or Registered Architect (RA) stamp on many temporary assembly filings. Rather than glossing over that, our 40-city permit directory and studio jurisdiction picker surface explicit PE/RA stamp notices upfront and position the DXF export as a clean scaled base file a licensed engineer can review and stamp rather than starting from scratch.</p>
<h2>Key Takeaways</h2>
<ul>
<li><strong>Pure TS engines shine on edge runtimes:</strong> Running identical geometry and vector-PDF code in both the browser and Cloudflare Workers eliminates client/server drift and keeps infrastructure overhead near zero.</li>
<li><strong>Vector PDFs beat screenshots every time:</strong> Mapping feet directly to PDF points (<code>pdf-lib</code>) gives fire marshals razor-sharp architectural prints at exact <code>1/16" = 1'-0"</code> scale in under 50 milliseconds.</li>
<li><strong>Single-session value beats gated trials:</strong> Letting an event crew load a preset (like a 40x60 heated holiday tent), verify all 9 fire-code checks, and inspect the watermarked 3-sheet PDF before ever creating an account removes friction while showing exact engineering output upfront.</li>
</ul>
<p>You can try the interactive studio, city permit directory, and IFC calculators directly at <a href="https://www.egresscad.com/?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=cad_workers">EgressCAD</a>.</p>
]]></content:encoded></item></channel></rss>