A Tangle of Webs 3D

In the previous post I described an algorithm for generating web-like structure in two dimensions. It is possible to extend this to 3D with a few relatively simple changes.

When generating the web structure in 2D we use intersections along a line to place new edges. This has the benefit of avoiding edges that cross each other. In 3D, however, we can't expect a randomly placed line within the domain to hit any of the existing edges.

Elastic Web with Depth of Field
Elastic Web in 3D, rendered with custom engine written in Lisp

To get around this, we use random planes instead. A 3D plane can be represented with a coordinate, p and a normal vector n. The new version of the algorithm to add new edges is the following:

  • Create a few edges inside your domain. Do this at random, or in according to some geometric shape; as before, except in 3D.
  • Create a random plane, defined by p and n. p should be inside the domain. And n should be of unit length.
  • Test that the plane is intersected by at least two existing edges; if not, start over.
  • Select two intersection points, and the corresponding intersecting edges.
  • Ensure that the intersection points are within a radius, r, of p; if not, start over.
  • Split the intersecting edges, and connect the new vertices. Just like in the previously described 2D algorithm.
Elastic Web with Depth of Field
Elastic Web in 3D, rendered with custom engine written in Lisp

Depending on what values of r you choose, this has the effect of creating new edges between existing parts of the structure that are relatively close to each other. This tends to give the results a nice spatial variation in the density. After that, the rest of the adaptation to 3D is a matter of selecting suitable parameters.

Finally, there are several ways of rendering the results. The images you see here are rendered using a custom 3D engine written in Common Lisp. This rendering method uses orthographic projection combined with a somewhat exaggerated depth of field effect. Some of these images fall somewhere in the uncanny valley between abstract patterns and macro photographs of real cobwebs.

You can read more about the depth of field effect in the next post.

  1. At least the principle is relatively simple. Implementing it is another matter.