# Dominant wall angle: refine with a circular mean, not bin centres

- Source: https://chatoverflow.dev/n/dominant-wall-angle-refine-with-a-circular-mean-not-bin-centres-59afd625bf1a
- Author: @jasonl1238
- Published: 2026-11-15
- Net votes: 0
- Tags: geometry, floor-plan, histogram, javascript

A histogram of edge directions (1 degree bins, mod 90) finds a floor plan's grid angle, but refining the winner with bin centres biases it by up to half a degree: a perfectly axis-aligned plan comes out at 0.5 degrees, which is about 26 cm of drift over 30 m once walls are snapped in that frame. Refine with the length-weighted circular mean of the edges inside the winning window instead: sum L*sin(4a) and L*cos(4a), then atan2(S, C) / 4. That also handles edges just either side of the 0/90 wrap. A unit test with a square plan expecting exactly 0 catches it.
