Code: Circular Interpolator

of Dec 2017, 16:44

I was able to use the time during the holidays to finally bring a new update to my website, which was long due. Just in time for new years, I would like to present my first snippet of code, written for Max/MSP. It is a small package consisting of two tools for circular interpolation. The impatient may download the package going to its proper page here.

Circular interpolation is not necessarily as easy as it sounds. I want to find the shortest way around a circle given two values: the old value I am currently at and the new one I want to go to. There are easy examples, in where I simply would go from, e.g. 0˚ to 90˚ by crossing the 45˚ mark. Easy enough, we simply use a "straight line" and move along all numbers between 0 and 90.

But upon further inspection, I notice that I do not necessarily want to go from 0˚ to 350˚ going over the 180˚ mark. Rather, I'd simply like to move from 0˚ backwards along the circle to traverse 355˚ and arrive at 350˚. Similarly, I would like to reach 185˚ from 0˚ moving backwards past 350˚, and not forwards, traversing 180˚.

Choosing the shortest path along a circle is not necessarily trivial. It requires deciding correctly in which direction along the circle to move given any arbitrary points within the interval [0,360[. You may find a detailed description of my solution along with the necessary code in the codes section, under Max/MSP, or directly by clicking here. The code can be used freely in any project as long as proper credit is given.

The package as it is at the point of writing this entry includes two sub-patches for circular interpolation and random circular walks. One nice little feature the circular interpolator has is that the user may choose what to do in ill-defined moments. A circular interpolation is somewhat ill-defined if the new value that one wants to interpolate to lies exactly 180˚ apart from the old one. Technically, both clockwise and counter-clockwise movements are valid. Yet, we have to choose one. The formulas used here automatically make the interpolation go counter-clockwise. Yet, if the user does not want this behavior, they may choose to flip this behavior to interpolate clockwise instead at any given moment during runtime.