In earlier posts, I mentioned finding polynomials, riffing off of damped harmonic motion, and then hitting on exponential spirals all trying to come up with a nice looking way to snap game tiles back into place when they are released. I want them to overshoot and then settle into place rather than snap directly into their spot.
The Basic Spiral
I am talking about a simple spiral of the form:
That would be an equation for a spiral that starts at the origin and heads outward as increases. For my application though, I want to end at the origin so I need to substitute in for .
The math is also going to work out slightly better if I use in place of in the above equations:
I don’t want the piece to spiral into place when released though. So, really, I am concerned with just the coordinate from the above equations:
To normalize everything, I am going to let . And, since I want my interpolation value to go from zero to one instead of one to zero, I am again going to subtract this all from one:
Parametrizing by Arc Length
If I just plot the spiral as is, then I am stuck with the same problem that I had with damped spring motion: the frequency is constant. The rate at which it would shimmy would not increase. I want it to really settle into place. So, I have to walk through the spiral at a fixed rate. I need to rescale the into something else so that for any given time interval, I cover the same arc length on the spiral.
The first step then is to figure out how much arc length I sweep out with any given . Call this arc length :
Then, to rescale my , I want to use instead so that . So, when , for example, I will need to find the such that the arc length covered in the first seconds is -th of the arc length covered in the whole interval. Solving for in the equation comes out to:
Plugging all of that back into the equation for gives me:
The simplest spiral here has , and we will go around four times with :
You can see how the period speeds up toward the end. This was a good starting point. However, the first oscillation goes almost as far beyond the target as our initial point was. So, I upped the exponent to :
This was pretty much the effect I wanted. Unfortunately, it involves taking an -th power, an -th root, and a cosine of calculation. I decided that was close enough to one to give it a whirl without needing the -th power.
Here you can see the final result.