All the efforts of the human mind cannot exhaust the essence of a single fly.

-- Thomas Aquinas

I learned about the flight path of insects when I read The God Delusion by Richard Dawkins several years back. Probably this was my favorite point of the book, I enjoy when he gets more technical. I don't like Dawkins harsh attitude in several occasions, and the book is no exception, but it was a nice read, recommended.

I always found it curious how insects rotate and curl up around light, but I was never curious enough to research why, so when Dawkins provided his simple evolutionary explanation, I enjoyed very much.

The explanation is very simple: flies, moths, etc, evolved in an environment where there was one kind of light, the natural light. Natural light, from Sun, moon and stars, is very far, so far that we can almost model it as coming from an infinite distante point. Such kind of light can be used as a guide to travel a straight route, and that's what insects do, they use natural light to route their trajectories. You can easily imagine yourself doing the same, one just need to look at the Sun and try to walk a long path maintaining the Sun at the same vision spot as it was originally. That's also how to navigate using the stars.

OK, then enter humans with their great inventions and creates a different kind of light source, the artificial light source, which is a geometrically different kind of light source, it's close, and it's focal.

Insects know only how to behave with natural light, and in the presence of artificial light, they just behave the same, when they want to follow a straight path they follow the path that maintains the light source at the same vision spot as it was originally. This is all nice for a distant light source, but for a focal one, you end up rotating or curling up around the source just to maintain it at the same vision spot.

This was more or less Dawkins explanation if I recall correctly, it's called transverse orientation (there are still controversies around this theory though). At the time I wished to write down the equations as an exercise but postponed it forever, until now, since now I have a blog with \(\KaTeX\) ☻.

Let \(\vec{p}\) denote the fly's position vector taking the light source as the origin, \(\vec{v}\) its velocity and \(\hat{p}\) the unit vector along \(\vec{p}\).

The fly should maintain the light source in the same vision spot. Assuming the absolute value of \(\vec{v}\) (the insect's mean velocity) doesn't change, it implies that \(\vec{v} \cdot \hat{p}\) must always be the same. This means that no matter when we check the angle that \(\vec{v}\) makes with \(\vec{p}\), it's always the same. So we have that \(\vec{v} \cdot \hat{p} = \vec{v}_0 \cdot \hat{p}_0 = v \cos{\phi} = constant\). Since \(\vec{v} = \frac{d\vec{p}}{dt}\) we have:

\[\frac{d\vec{p}}{dt} \cdot \hat{p} = \frac{dp}{dt} = \vec{v}_0 \cdot \hat{p}_0 = v \cos{\phi}\]

where \(\phi\) is the angle between \(\vec{v}_0\) and \(\vec{p}_0\).

By integration we get:

\[p = p_0 + \frac{\vec{v}_0 \cdot \vec{p}_0}{p_0}t = p_0 + (v \cos{\phi}) t\]

This equation means that the fly constantly distances/approaches the light source (notice that I freely exchanged \(\hat{p}_0\) for \(\frac{\vec{p}_0}{p_0}\)).

The velocity along \(\vec{p}\) is just one component of the velocity, in a bidimensional analysis the other component may be constructed over the direction perpendicular to \(\vec{p}\) by rotating it \(\frac{\pi}{2}\) counter-clockwise, I'll denote such vector by \(\vec{p}^\bot\). So the velocity component over this vector is \(\vec{v} \cdot \hat{p}^\bot\), and as with the other component, this one should also be constant: \(\vec{v} \cdot \hat{p}^\bot = constant = \vec{v}_0 \cdot \hat{p}^\bot_0\). Since this component is tangential to the circumference of radius \(p\), we have that:

\[p \omega = \vec{v} \cdot \hat{p}^\bot = \vec{v}_0 \cdot \hat{p}^\bot_0 = v \sin{\phi}\]

Where \(\omega\) is the angular velocity, so we have that:

\[ \begin{aligned} p \frac{d\theta}{dt} &= v \sin{\phi} \\\\ \frac{1}{v \sin{\phi}} \frac{d\theta}{dt} &= \frac{1}{p} \\\\ \int \frac{1}{v \sin{\phi}} \frac{d\theta}{dt} dt &= \int \frac{1}{p} dt \\\\ \frac{1}{v \sin{\phi}} \theta + c_1 &= \int \frac{1}{p_0 + (v \cos{\phi}) t} dt \\\\ \frac{1}{v \sin{\phi}} \theta + c_1 &= \frac{1}{v \cos{\phi}} \ln(p_0 + (v \cos{\phi}) t) + c_2 \\\\ \frac{1}{v \sin{\phi}} \theta &= \frac{1}{v \cos{\phi}} \ln(p_0 + (v \cos{\phi}) t) + c_3 \\\\ \theta &= (\tan{\phi}) \ln(p_0 + (v \cos{\phi}) t) + c_4 \\\\ \theta &= (\tan{\phi}) \ln(p_0) + (\tan{\phi}) \ln\bigg(1 + \bigg(\frac{v}{p_0}\cos{\phi}\bigg)t\bigg) + c_4 \\\\ \theta &= \theta_0 + (\tan{\phi}) \ln\bigg(1 + \bigg(\frac{v}{p_0}\cos{\phi}\bigg)t\bigg) \end{aligned} \]

So these are the parametric polar equations which give us position through time:

\[p = p_0 + (v \cos{\phi}) t \quad \theta = \theta_0 + (\tan{\phi}) \ln\bigg(1 + \bigg(\frac{v}{p_0}\cos{\phi}\bigg)t\bigg)\]

From the second one it follows that:

\[ \begin{aligned} \theta &= \theta_0 + (\tan{\phi}) \ln\bigg(1 + \bigg(\frac{v}{p_0}\cos{\phi}\bigg)t\bigg) \\\\ (\cot{\phi})(\theta - \theta_0) &= \ln\bigg(1 + \bigg(\frac{v}{p_0}\cos{\phi}\bigg)t\bigg) \\\\ e^{(\cot{\phi})(\theta - \theta_0)} &= 1 + \bigg(\frac{v}{p_0}\cos{\phi}\bigg)t \\\\ p_0 e^{(\cot{\phi})(\theta - \theta_0)} &= p_0 + (v\cos{\phi})t = p \end{aligned} \]

Which gives the polar equation of the trajectory:

\[p = p_0 e^{(\cot{\phi})(\theta - \theta_0)}\]

\(r=ae^{b\theta}\) is the equation of the Spira mirabilis, also known as the logarithmic spiral, equiangular spiral or growth spiral.

Polar equations are nice but when one wishes to build animations, having the Cartesian ones is handy. Assuming:

\[\vec{p} \equiv \begin{pmatrix} x \\ y \end{pmatrix} \quad \vec{p}_0 \equiv \begin{pmatrix} x_0 \\ y_0 \end{pmatrix} \quad \vec{v}_0 \equiv \begin{pmatrix} \dot{x}_0 \\ \dot{y}_0 \end{pmatrix} \quad R(\theta) \equiv \begin{bmatrix} \cos{\theta} & - \sin{\theta} \\ \sin{\theta} & \cos{\theta} \end{bmatrix}\]

I've made the conversion from polar parametric equations to Cartesian parametric, which gives:

\[\vec{p} = e^{(\cot{\phi})f(t)} R(f(t)) \vec{p}_0\]

where

\[ \begin{aligned} f(t) &= (\tan{\phi})\ln\bigg(1 + \bigg(\frac{v}{p_0}\cos{\phi}\bigg)t\bigg) \\\\ \tan{\phi} &= \frac{x_0 \dot{y}_0 - y_0 \dot{x}_0}{x_0 \dot{x}_0 + y_0 \dot{y}_0} \\\\ \cos{\phi} &= \frac{x_0 \dot{x}_0 + y_0 \dot{y}_0}{\sqrt{x_0^2 + y_0^2}\sqrt{\dot{x}_0^2 + \dot{y}_0^2}} \end{aligned} \]

When \(\phi \in \big\{\frac{\pi}{2}, -\frac{\pi}{2}\big\}\) the trajectory reduces to a circle since the fly will have no component of velocity along \(\vec{p}\). Given that:

\[\lim_{\phi \to \frac{\pi}{2}} f(t) = \frac{v}{p_0}t \quad \lim_{\phi \to -\frac{\pi}{2}} f(t) = -\frac{v}{p_0}t\]

The equations in these special cases reduces to:

\[ \vec{p} = \begin{cases} R\bigg(\frac{v}{p_0}t\bigg) \vec{p}_0 & \phi = \frac{\pi}{2} \\\\ R\bigg(-\frac{v}{p_0}t\bigg) \vec{p}_0 & \phi = -\frac{\pi}{2} \end{cases} \]

And when \(\phi \in \{0, \pi\}\), which means no tangential velocity, the equation reduces to a straight line:

\[\vec{p} = \vec{p}_0 + \vec{v}_0 t, \quad \phi \in \{0, \pi\}\]

We can also assume this is the case for when \(\vec{p}_0 = \mathbf{0}\) or \(\vec{v}_0 = \mathbf{0}\). Putting together all the pieces and edge cases:

\[ \vec{p} = \begin{cases} \vec{p} = \vec{p}_0 + \vec{v}_0 t & \vec{p}_0 = \mathbf{0} \lor \vec{v}_0 = \mathbf{0} \lor \phi \in \{0, \pi\} \\\\ R\bigg(\frac{v}{p_0}t\bigg) \vec{p}_0 & \phi = \frac{\pi}{2} \\\\ R\bigg(-\frac{v}{p_0}t\bigg) \vec{p}_0 & \phi = -\frac{\pi}{2} \\\\ e^{(\cot{\phi})f(t)} R(f(t)) \vec{p}_0 & otherwise \end{cases} \]

where

\[ \begin{aligned} f(t) &= (\tan{\phi})\ln\bigg(1 + \bigg(\frac{v}{p_0}\cos{\phi}\bigg)t\bigg) \\\\ \tan{\phi} &= \frac{x_0 \dot{y}_0 - y_0 \dot{x}_0}{x_0 \dot{x}_0 + y_0 \dot{y}_0} \\\\ \cos{\phi} &= \frac{x_0 \dot{x}_0 + y_0 \dot{y}_0}{\sqrt{x_0^2 + y_0^2}\sqrt{\dot{x}_0^2 + \dot{y}_0^2}} \end{aligned} \]

The following is an illustration making use of these equations:

Source code (in PureScript):

(thanks Jonas Platte for tips on resetting the animation)

As stated formally, this is a mathematical analysis of the problem in the plan. A tridimensional analysis is left for a future post.

I have indeed seen in my lifetime some drunk annoying bugs that were following the path of a Conchospiral.

Now on the nature of things: was really man that first introduced focal light sources?

One of theses days I glimpsed something bright in the darkness, which brought me memories of my childhood, where even while living in the metropolitan area, sometimes I would see a firefly, ladybug or even a butterfly. Not today anymore, it has been years I don't see anything of this, and a firefly I've seen like 3 times in my entire lifetime. I felt a bit sad for the childhood of today and tomorrow, these days I/they only see Aedes aegypti (Nature, always adapting...). This prompted me to take a look on the web about what was going on. Of course it always boils down to the side effects of the presence of man in Nature.

I found a nice (brazilian portuguese) article explaining this, which also made me learn about an awesome especies of lighting termite mound that exists here in Brazil and which sadly is in risk of extinction. I learned they are even touristic creatures. Here's a recent and awesome video about them by an english speaker adventurer:

And this is the first part (there're three) of an in deep (brazilian) reporter about them:

The lighting comes from a kind of firefly (Pyrearinus termitilluminans) that lives its larvae state in termite mounds (lighting them) and what I found more interesting is how they get fed. The video shows that other flying insects somehow end up hitting the mounds and get trapped by the lighting firefly larvae, it's bioluminescence for hunting other flying insects. Sounds familiar huh? But also, it serves for the purpose of guiding flying termites to other mounds for mating!

I can't recall where I watched someone quoting about not existing anything that man invented that Nature didn't invent it first. I tried to find the movie/quote where I've seen that but failed and ended up finding this quote:

Nothing is invented, for it's written in Nature first.

-- Antoni Gaudí

And this book:

The book seems worth a read, it may be some gem from the 80's. The cover is quite suggestive and it's very on topic.