DEV Community

Clara Sutton
Clara Sutton

Posted on Originally published at plancaliber.com

Computing Recessed Lighting H/2 Grid Coordinates & NEC Load Audits in TypeScript

Laying out recessed LED downlights by eyeballing a ceiling grid almost always creates one of two problems: dark scallops along the perimeter walls or overlapping bright pools down the middle of the room.

Inside PlanCaliber's Recessed Lighting Spacing & NEC Load Calculator, we solve ceiling layouts with a dual-constraint TypeScript grid solver that enforces both the standard H / 2 beam-overlap rule (maximum on-center spacing equals half the ceiling height) and room-specific foot-candle / lumen targets, then emits exact X and Y framing coordinates ready for a reflected ceiling plan (Sheet E-101).

1. Dual-Constraint Grid Solver (H/2 Rule + Target Lumens)

First compute the maximum allowed spacing from ceiling height (ceilingHeightFt / 2) and the minimum fixture count needed to reach the room's target lumen density (lumensPerSqFt * area / fixtureLumens). Then expand whichever axis currently has the widest center-to-center spacing until both constraints hold simultaneously:

export type WallOffsetMode = 'half_spacing' | 'fixed_30in';

export interface CeilingGridInput {
  roomLengthFt: number;
  roomWidthFt: number;
  ceilingHeightFt: number;
  lumensPerSqFt: number;
  fixtureLumens: number;
  wallOffsetMode: WallOffsetMode;
}

export interface CeilingGridResult {
  cols: number;
  rows: number;
  fixtureCount: number;
  spacingXFt: number;
  spacingYFt: number;
  xCoordsFt: number[];
  yCoordsFt: number[];
  maxRecommendedSpacingFt: number;
}

const round2 = (v: number) => Math.round(v * 100) / 100;

export function solveCeilingGrid(input: CeilingGridInput): CeilingGridResult {
  const { roomLengthFt, roomWidthFt, ceilingHeightFt, lumensPerSqFt, fixtureLumens, wallOffsetMode } = input;

  // 1. Height / 2 uniform beam-overlap rule
  const maxRecommendedSpacingFt = round2(ceilingHeightFt / 2);

  // 2. Minimum fixtures required for target task/ambient lumens
  const targetLumens = Math.round(roomLengthFt * roomWidthFt * lumensPerSqFt);
  const minFixturesForLumens = Math.max(1, Math.ceil(targetLumens / fixtureLumens));

  let cols = roomLengthFt <= maxRecommendedSpacingFt ? 1 : Math.max(2, Math.ceil(roomLengthFt / maxRecommendedSpacingFt));
  let rows = roomWidthFt <= maxRecommendedSpacingFt ? 1 : Math.max(2, Math.ceil(roomWidthFt / maxRecommendedSpacingFt));

  // Balance aspect ratio while meeting lumen target
  while (cols * rows < minFixturesForLumens) {
    if (roomLengthFt / cols >= roomWidthFt / rows) {
      cols += 1;
    } else {
      rows += 1;
    }
  }

  // 3. Perimeter offset strategy: standard S/2 half-spacing vs fixed 30" counter-edge wash
  const computeAxis = (spanFt: number, count: number) => {
    if (wallOffsetMode === 'fixed_30in') {
      if (count === 1) return { offset: spanFt / 2, spacing: 0 };
      const offset = Math.min(2.5, spanFt / 4);
      return { offset, spacing: (spanFt - 2 * offset) / (count - 1) };
    }
    const spacing = spanFt / count;
    return { offset: spacing / 2, spacing };
  };

  const axisX = computeAxis(roomLengthFt, cols);
  const axisY = computeAxis(roomWidthFt, rows);

  const xCoordsFt = Array.from({ length: cols }, (_, i) => round2(axisX.offset + i * axisX.spacing));
  const yCoordsFt = Array.from({ length: rows }, (_, j) => round2(axisY.offset + j * axisY.spacing));

  return {
    cols,
    rows,
    fixtureCount: cols * rows,
    spacingXFt: round2(axisX.spacing),
    spacingYFt: round2(axisY.spacing),
    xCoordsFt,
    yCoordsFt,
    maxRecommendedSpacingFt
  };
}
Enter fullscreen mode Exit fullscreen mode

2. Why fixed_30in Matters in Kitchens vs half_spacing in Living Rooms

In a living room or basement rec room, placing the first row at spacing / 2 from each wall gives even wall washing and balanced shadows. In a kitchen with 24"-deep base cabinets and 12"-deep uppers, a half_spacing offset of 24" puts the downlight right over the front edge of the upper cabinet, casting a shadow onto the countertop below. Switching to fixed_30in (2.5 ft off the finished wall) centers the beam directly over the front work zone of the countertop.

3. Continuous-Load Circuit Check & Sheet E-101 Export

Once cols * rows is solved, checking breaker capacity under the 80% continuous-load rule (15A * 120V * 0.80 = 1,440W, or 20A * 120V * 0.80 = 1,920W) takes one line, and formatting coordinates to feet-and-inches (formatFeetInches) lets electricians snap chalk lines directly off the framing plates.

You can copy our Recessed Lighting H/2 & NEC 210.52 Formula Workbook (Google Sheets), download the 8-Sheet Vector PDF Lighting Field Guide, or open the room in the PlanCaliber 2D/3D CAD Studio to place switches, GFCI outlets, and fixtures on layer E-POWR.

Free browser drafts export an instant 1400x1050 watermarked proof PNG; one-time passes unlock clean 1/4"=1'-0" 2-sheet vector PDFs ($9) or full 5-sheet CAD sets including Sheet E-101 and 8-layer AutoCAD R12 .DXF ($19), with 14-day instant refunds.

Note: Preliminary layout and estimating tool only. Verify circuit loads, IC/wet-location ratings, joist locations, and local NEC/AHJ requirements on site with a licensed US electrician or qualified design professional before installation.

Top comments (0)