2018-05-05

I maded a film

Reading Devaney’s An Introduction to Chaotic Dynamical Systems, Second Edition I found the description of a solenoid (§2.5) quite interesting: It starts out as a torus, but then you repeatedly lengthen it, shrinking the radius, and fold it back on itself, much like you fold a hair tie, but with the difference that the volume is not retained, so that each folded form fits inside the previous one. I thought that it would be nice to make a recursive function to draw a solenoid to arbitrary depth, and then to make a raytraced animation of the solenoid developing. As it were, I couldn’t quite work out the proper recursive step, so the idea has been languishing for a while (like a couple of years or so).

A few weeks ago I decided that I would get a grip on myself and work out the proper function, since it was obviously simple, if nothing else so to make sure I’m not entirely senile. After a couple of nights of scratching sketches on paper I finally managed to work out the proper order of things and started to transfer data to POVRay, my preferred raytracer. And of course, since I fully subscribe to the idea that glass balls are an important feature of raytracing, I would make the solenoid out of virtual glass. It would also spin, so as to bring out the shape better (on the assumption that viewers would not have access to a stereo viewer).

I soon realised that it was inconvenient to run a C program to generate the coordinates of the object and transfer to a POVRay input file by cut-and-paste every time I wanted to tinker with anything. Happily it is possible to program directly in the POVRay scene description language, so I reimplemented the function and could then work more or less interactively in POVRay. Delaney proposes shrinking the radius of the tube by a factor 10 for each folding, but in my opinion that makes it disappear from view too fast, so I used a factor 3 instead.

My original idea was that I’d render each level and fade it out while fading in the next level, but it turned out to be rather complicated as the surface+interior computational model of POVRay doesn’t really have a concept of fading, to achieve this a large number of (non-linear) parameters have to be adjusted in synchrony. I pondered this a bit, but decided that while I might eventually work out how to do the transforms it was probably easier to instead do the fading on the resulting images, rather than the 3D models, so generated images with only a single object in each and then composited them using ImageMagick and a couple of awk scripts.

This looked OK, but I still wasn’t quite happy with the results, there should be more movement in the animation. In the end I rewrote the solenoid code a bit, so that there would be an animated transition where the next level double-coil shrinks and separates out of the previous level. On a whim I added a background texture and was happily surprised by how much this made the glassiness of the tube pop out and made its structure more distinctive. The full length video took almost a week to render, the later parts requiring about an hour per frame, as the object becomes more complex. For no particular reason I rendered the animation at PAL resolution, notionally at 25 frames/second, but that made the motion a bit too fast in my opinion, so I pulled the output framerate down to 10 fps when generating the video (with ffmpeg) from the individual frames rendered by POVRay. That could then be uploaded to YouTube:

If anyone wants the code to play around with, just ask in the comments.

No comments: