West sun is a constant worry for people who rent in Taiwan, and a listing photo can't show what it'll do in your room. I wanted to see the patch of light on the floor, so I built Sunspill.
What it does
You draw the room, up to four windows, a shade above each window and a building across the street. Pick a city from the built-in list and a date, then drag the clock. The patch moves across the floor and the walls. A second view colours the floor by the hours of direct sun per day, and a printed rule counts the afternoon sun after a time you choose.
Everything runs in the page. The app is one HTML file with a Content Security Policy that allows no network requests, so nothing leaves your browser. After the first visit it works offline.
How the light is found
The sun position comes from the NOAA equations. For each window I take the opening, trim it by the wall thickness (a beam has to clear both faces of the wall), and subtract the shadow that the eave and the building throw on the window plane. Each shadow is convex, so what's left is a few convex pieces.
Each piece is carried along the sun rays onto the floor and the walls and clipped to them. The room is convex, so a ray that gets in meets the boundary exactly once and nothing inside can block it. So there's no ray casting at runtime, and the polygons are exact instead of pixels.
How I checked it
Sun position: 403 samples in 15 cities against the NREL Solar Position Algorithm through pvlib. Elevation is within 0.007 degrees and azimuth within 0.06 degrees.
Window light: I wrote a second program that shares no code with the first. From a point in the room it follows the ray toward the sun through the wall, the shade and the building and asks whether it gets out of a window. On 3,767 random rooms and 3.77 million probe points the two disagree 0 times. Writing the comparison turned up a real bug: light below a raised plane was dropped from the wall patches. It's fixed and tested now.
What it does not do
Clear sky and direct sun only. No reflections, no furniture shadows, one box shaped room. The model has never been compared with a photograph of a real room, so treat the patch as a geometric prediction. If you can measure a room, an issue with a photo would help more than any feature.
The source is MIT licensed: https://github.com/Arthur031221/Sunspill. The sun and light code is also a small library with no dependencies.

Top comments (0)