Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to calculate shadow areas of buildings or simulate shadows of buildings in a city, using the heights of these buildings and the sun angle and azimuth?

The basic light tracing concept using trigonometry is known. However, how would one come up with simulated shadow of group of buildings in one place?

share|improve this question
Cool question. I wonder though if you might get better initial responses from the new Physics StackExchange? – Peter Boughton Nov 10 '10 at 10:55
Note that a group of buildings are prone to shadowing both their surroundings and each other. This may affect what it considered 'shadow area'. – 9000 May 18 '15 at 14:12
You would also need to know building's ground plan and positions. – Euphoric May 18 '15 at 14:39

Yes, this is a matter of projecting the geometry of the buildings onto a shadow plane along the sun angle, and then computing the union of the resulting polygons. This gives a single polygon that you can then get the area of by simple triangle subdivision. All of these features are actually built into your graphics card these days.

If your buildings are non-polygonal and you need a precise answer you're out of luck unless you can model them mathematically, but really that's a rare case these days--everything's built of polygons, and/or you can get away with an approximated answer.

For a specific solution, I'd recommend asking this question on Stack Overflow.

share|improve this answer

Yes, of course this is possible. It is called ray tracing.

Being old and grey means I can remember when ray tracing was exclusively the province of large supercomputers. It is now routinely assigned as an undergraduate computer graphics class programming assignment, and the results can be STUNNING.

Take a look at this, for some examples of what the kids are doing these days.

share|improve this answer
I'm pretty young yet, but I've read a bit about what PCs used to be capable of, and yes, it's pretty amazing how far we've come. – Michael K Nov 10 '10 at 13:27
I'm still waiting for real-time raytracing. We're getting close! – Alex Feinman Nov 10 '10 at 17:54

Are you actually ray-tracing? If so, you backtrace from the point being rendered to the light source. If it intersects one of the buildings, its in a shadow.

If you are using OpenGL/DirectX for real-time graphics, there are other solutions - look around online as thats a fairly big topic.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.