If you try to render an architectural floor plan on HTML5 <canvas> or in SVG by stroking thick centerlines (ctx.lineWidth = wallThickness), the drawing breaks down on the very first house you load:
- Notched L-corners:
lineCap = 'butt'leaves a triangular bite out of every exterior corner. - Mixed-thickness mismatches: When a
6.5"exterior insulated wall meets a4.5"interior drywall partition,lineJoin = 'miter'cannot even run because they are separate strokes with different thicknesses. - 3D Z-fighting at T-junctions & X-junctions: Extending every wall segment to the shared centerline vertex makes overlapping coplanar faces flicker in WebGL and produces broken overlaps in AutoCAD
.DXFand.OBJexports. - Hacking door & window cutouts: Painting a white rectangle over a dark wall stroke works poorly in 2D (it smears grid lines and room fills) and does nothing for 3D wall piers, window sills, and door headers.
In PlanCaliber, every wall is compiled into exact mitered 2D quads and analytic 3D solid pieces (WallSolidPiece) using one deterministic joint solver in pure TypeScript — zero CSG boolean libraries, zero flickering seams.
Here is the exact math and edge-case handling behind computeWallEndCap and buildSolvedWalls.
Step 1: Collect Oriented Incident Walls at Every Vertex
For every vertex in the floor plan, build an adjacency list of incident walls with unit vectors pointing outward from that joint:
for (const w of doc.walls) { const a = vMap.get(w.startId); const b = vMap.get(w.endId); if (!a || !b) continue; const dx = b.x - a.x; const dy = b.y - a.y; const len = Math.hypot(dx, dy); if (len < 1e-3) continue; incident.get(w.startId)!.push({ wall: w, dirOut: { x: dx / len, y: dy / len } }); incident.get(w.endId)!.push({ wall: w, dirOut: { x: -dx / len, y: -dy / len } }); } From here, every wall endpoint falls into one of four clean topological cases based on others = incident.filter(i => i.wall.id !== wall.id).
Step 2: Mixed-Thickness L-Corner Miters (With Acute-Angle Clamp)
When others.length === 1 and the two walls are not collinear (dot >= -0.985), each wall has two parallel boundary lines offset by ± thicknessIn / 2 from its centerline.
By intersecting the matching left-side offset lines and right-side offset lines via 2D line intersection, a 6.5" exterior wall and a 4.5" partition meet cleanly at an exact miter point — no gap on the outside, no overhang on the inside:
const otherHalfT = other.wall.thicknessIn / 2; const inOther = { x: -other.dirOut.x, y: -other.dirOut.y }; const orientSign = atStart ? 1 : -1; const otherMatchLeft = { x: -inOther.y * orientSign, y: inOther.x * orientSign }; const pSelfLeft = { x: pSelf.x + leftNorm.x * halfT, y: pSelf.y + leftNorm.y * halfT }; const pOtherLeft = { x: pSelf.x + otherMatchLeft.x * otherHalfT, y: pSelf.y + otherMatchLeft.y * otherHalfT }; const interLeft = lineIntersection2D(pSelfLeft, dirOutFromJoint, pOtherLeft, other.dirOut); const pSelfRight = { x: pSelf.x - leftNorm.x * halfT, y: pSelf.y - leftNorm.y * halfT }; const pOtherRight = { x: pSelf.x - otherMatchLeft.x * otherHalfT, y: pSelf.y - otherMatchLeft.y * otherHalfT }; const interRight = lineIntersection2D(pSelfRight, dirOutFromJoint, pOtherRight, other.dirOut); // Prevent extreme miter spikes on sharp acute angles (< ~25 deg) const clampMiter = (pt: Point2D | null, fallback: Point2D): Point2D => { if (!pt) return fallback; const d = Math.hypot(pt.x - pSelf.x, pt.y - pSelf.y); if (d > Math.max(wall.thicknessIn, other.wall.thicknessIn) * 2.2) return fallback; return pt; }; Notice the 2.2 × maxThickness miter limit: if a user drags an angled bay wall to a very tight acute corner, the solver falls back to a clean bevel cap instead of firing a 4-foot needle off the sheet.
Step 3: Priority Trimming at T-Junctions & X-Junctions
Once a vertex has degree >= 3, miter intersections no longer apply — you need clean architectural butt-trimming so walls never overlap:
- T-junction: One pair of incident walls is collinear (
dot < -0.97). That collinear pair is the through-wall (trimDistIn = 0). The perpendicular stem wall trims back bymaxPerpHalfT(half the through-wall's thickness) so its drywall butts flush against the through-wall's face. - X-junction: Two collinear pairs cross. We rank by structural priority (
exterior = 3,interior = 2,half_wall = 1, deterministic ID tie-break). The higher-priority wall runs unbroken; the lower-priority crossing wall trims back byhigherCross.wall.thicknessIn / 2.
const higherCross = perpNeighbors.find((p) => { const pHasCollinear = others.some( (o2) => o2 !== p && p.dirOut.x * o2.dirOut.x + p.dirOut.y * o2.dirOut.y < -0.97 ); if (!pHasCollinear) return false; if (wallPriority(p.wall.kind) !== wallPriority(wall.kind)) { return wallPriority(p.wall.kind) > wallPriority(wall.kind); } return p.wall.id < wall.id; }); const trim = higherCross ? higherCross.wall.thicknessIn / 2 : 0; That eliminates 100% of overlapping faces in Three.js 3D cutaways AND prevents duplicate double-lines when exporting to AutoCAD .DXF and vector PDFs.
Step 4: One Cap Solver Feeds Both 2D Cutouts & 3D Piers/Sills/Headers
Once startCap and endCap are computed, slicing a wall around its hosted doors and windows becomes a simple 1D interval sweep from effStart to effEnd:
const quadForSpan = ( d0: number, d1: number, useStartCap: boolean, useEndCap: boolean ): [Point2D, Point2D, Point2D, Point2D] => { const p0 = useStartCap ? startCap.leftPoint : { x: a.x + dirX * d0 + normX * halfT, y: a.y + dirY * d0 + normY * halfT }; const p3 = useStartCap ? startCap.rightPoint : { x: a.x + dirX * d0 - normX * halfT, y: a.y + dirY * d0 - normY * halfT }; const p1 = useEndCap ? endCap.leftPoint : { x: a.x + dirX * d1 + normX * halfT, y: a.y + dirY * d1 + normY * halfT }; const p2 = useEndCap ? endCap.rightPoint : { x: a.x + dirX * d1 - normX * halfT, y: a.y + dirY * d1 - normY * halfT }; return [p0, p1, p2, p3]; }; Walk the sorted hostedOpenings along the wall:
- Solid pier before/between/after openings:
quadForSpan(cursor, opening.s, ...)-> full height0towallH(9'-0"), drawn as crisp filled poché in 2D and extruded as a solid prism in 3D. - Door opening (
sillHeightIn = 0): Empty gap in 2D (where the door leaf and 90° quarter-circle swing arc render cleanly over the floor fill!) + one 3D header lintel box from80"(6'-8") to108"(9'-0"). - Window opening (
sillHeightIn = 36",headHeightIn = 84"): Crisp glass & frame lines in 2D + two analytic 3D solids (sill wall0" -> 36", header wall84" -> 108").
Zero CSG mesh booleans, zero degenerate triangles, and every 2D opening aligns to the exact sixteenth of an inch with the 3D cutaway.
Step 5: Free Bonus — Clear Drywall-to-Drywall Interior Span
Because computeWallEndCap already computes each perpendicular wall's intrusion (perpInsetIn = otherHalfT * sinAngle), you immediately get the true clear interior wall length:
const clearInteriorLengthIn = Math.max( 0, Number((lengthIn - startCap.perpInsetIn - endCap.perpInsetIn).toFixed(4)) ); When a user lays out a 12'-0" centerline kitchen wall bounded by two 6.5" exterior walls, the cabinetry and clearance engine automatically knows the clear drywall-to-drywall run is 11'-5 1/2" — preventing cabinets or appliances from colliding with corner framing.
Test the Miter & Cutaway Engine Live
You can drag walls, place mixed-thickness partitions, cut doors and egress windows, and watch the 2D poché, 3D cutaway, and scaled 1/4" = 1'-0" blueprint PDF update live in your browser (free to draft and inspect):
- Open the Blueprint & DXF Studio: PlanCaliber Blueprint & AutoCAD .DXF Maker
- Try AI Sketch-to-CAD: Convert a Hand Sketch or PDF to Scaled CAD
- Check Print Scale Math: Free Architectural Floor Plan Scale Calculator
Note: PlanCaliber generates preliminary space-planning drawings; always verify final dimensions and code compliance on site before construction.
