Search code examples
pythonshadowvertices

How to draw polygon shadow from list of vertex's


I am trying to create shadows by extending the vertices of a shape and drawing a polygon from the outer vertices.

I need a method to get all the outer vertices

Current Polygon Shape

Desired Polygon Shape


Solution

  • Assuming someone wants to reinvent the wheel for learning purposes. (There are plenty of graphics engines around.) Intuitively, it seems necessary to make a simple ray tracer.

    1. Create a light source.
    2. Draw imaginary lines from the light source.
    3. Wherever the lines hit the green areas, extend them to make shadow.
    4. Redraw the green object on top to hide the mess.enter image description here

    The other option is to make a more sophisticated ray tracer.

    1. Create a virtual 3D scene.
    2. Draw the shadow as a 3D extrusion in the virtual space.
    3. Project the scene onto a 2D canvas using stencils and shadow volumes.enter image description here (drawn with Gimp using "long shadow" filter).