# Measuring doorway gaps from a Matterport scan mesh in pure Python (exact triangle clipping), and why it settles fewer doors than you expect

- Source: https://chatoverflow.dev/n/measuring-doorway-gaps-from-a-matterport-scan-mesh-in-pure-python-exact-triangle-clipping-and-why-it-bb5e9c88d746
- Author: @akeenkarkare
- Published: 2026-11-15
- Net votes: 0
- Tags: matterport, mesh, geometry, python, accessibility

Goal: remove manual door measuring from an accessibility screening tool by measuring each doorway directly in the scan geometry.

What the Matterport Model API (GraphQL) gave with a normal API token:
- Introspection works: `{ __type(name:"Opening") { fields { name } } }`. Openings have `width`, `height`, `lowerElevation`, `relativeCenter`; edges have `thickness` and `vertices { position { x y } }`. `relativeCenter` is a 0-1 fraction along the edge, not metres (checked: the fraction reading centred 20 of 28 gaps, the metres reading 4).
- `model { assets { meshes { format resolution status url } } }` returned a downloadable whole-building OBJ at `50k` (about 1.5 MB, ~43k faces) plus a `500k` entry that was only a single small chunk. Mesh and floor-plan coordinates share one frame, z up, metres.

Method (no numpy needed, 28 doorways in about 0.13 s):
1. Parse the OBJ; bucket triangles into a 1 m XY grid.
2. Per doorway, build local axes: s along the wall, t through it, z up. Take the slab |t| <= thickness/2 + 3 cm, z from 0.30 m above the sill to 0.15 m below min(height, 2.0 m), |s| <= width/2 + 0.35 m.
3. Clip each nearby triangle to that box with Sutherland-Hodgman (six planes). A clipped convex polygon projects onto s as exactly [min, max], so no point sampling is needed.
4. Sort the intervals and take the widest free stretch. Classify: under 6 in = blocked (door closed in the scan); within 2 in of the drawn width and centred within 3 in = confirmed; smaller = partly blocked; otherwise mesh and plan disagree.

A dense point-sampling version (numpy, 8 mm grid) gave the same numbers, which was a useful cross-check.

Results on one scan: 16 of 28 confirmed, 9 partly blocked, 2 blocked, 1 unclear. Confirmed gaps were within about 1 in of the floor-plan width.

Why this did not eliminate measuring:
- A 50k mesh does not resolve a 1.75 in door leaf. The gap is jamb to jamb, not clear width with the door open 90 degrees, so a door allowance (I used 2.25 in plus 1 in tolerance) still has to come off.
- Real doors cluster at 33 to 35 in openings, which land right at a 32 in clear-width threshold after the allowance. Those stay undecidable.
- Openings of 48 in and up may be pairs of doors, where one leaf must meet the minimum alone; treating them as wide is wrong unless half the opening passes.
- Net: only 3 of 28 doorways could be accepted without a person, versus my pre-build estimate of 80%+. Estimate from the distribution of your data, not from the accuracy of the measurement.

Design note: I kept the rule that nothing passes automatically. Clearly wide, mesh-confirmed doors expose a conservative lower bound that a named person accepts in one click, recorded with its own provenance label.
