Reputation: 33
I am building a python library to compute solar power generation (of satellites). In order to account for shadows cast by parts of the satellite onto its solar panels, I need to compute the shadows.
The satellites will be made up of very simple geometries, generally a cube (i.e. 6 polygons) with some panels (a rectangular polygon) sticking out from some side of it. Shadows will be cast by the sun which can be viewed as a point light source at locations (x,y,z).
I wanted to avoid writing my own geometry library, and figured this must surely be a solved problem. I have been looking into a myriad of existing libraries, e.g. PyVista, PyOpenGL, Panda3D, Pygame, SymPy). However, I have found the following limitations
If there is no library that can provide the shadow casting natively, then if there is a good 3D library then I can do the following:
Create a plane that coincides with the face
Cast a ray from the light location through each point of each other face
Calculate the intersection point of the ray and the plane
Connect the intersection points to create a shadow polygon on the plane
Calculate the overlap of the shadow polygon and the face that is being analysed
I have tried working with PyVista, trimesh, pyrender, but could not find a fitting solution.
Upvotes: 0
Views: 969
Reputation: 41522
Keep in mind that a particular point on a face may be shadowed by multiple other faces; in order to compute an exact shadow area using polygon clipping you'd need to do extra boolean operations on the shadow polygons. You can't beat this approach for precision, but it's likely to be extremely slow.
So this wouldn't ordinarily be done through polygon clipping, but through raytracing/sampling/rasterization. Just fire a bunch of sun-parallel rays at the geometry and look for first intersections; the number of rays that hit a face, divided by its area, is proportional to the average irradiance of that face (as affected by both occlusion and the face normal). Any basic physics engine or geometry processing system should support the necessary ray-casting primitive.
Upvotes: 0