Phony Physics (a.k.a. Fun with Interpolation) April 3rd, 2009
Patrick Stein

In a previous post, I mentioned looking for a polynomial for an application. I am working on an application that involves clicking or dragging tiles around. Once you release the tile, I want it to snap to where it’s supposed to be.

The easiest way to do this is to just warp it to where it’s supposed to go. This isn’t very visually pleasing. The next best thing is to set up a time-interval on which it moves into place. Then, linearly interpolate from where it is to where it’s going (here with t normalized to range between zero and one):

(1-t)x_0 + tx_1

That’s much better than just warping, but it doesn’t have any sort of fade-in or fade-out. It instantaneously has its maximum velocity and then instantaneously stops at the end.

Typically, then one uses a cubic spline to scale the t value before interpolating to get a speed up in the beginning and then slow down in the end.
Read the rest of this entry ⇒

Find the Polynomial You’ve Been Looking For April 2nd, 2009
Patrick Stein

Often, I want to have a polynomial that meets certain criteria. For most applications in the past, I figured it all out by hand.

Today, I was having trouble getting the conditions specified enough to get the sort of polynomial that I was expecting. After finding the coefficients for several sixth degree polynomials in a row, I figured I should instead be able to do something like this with the proper lisp:

(calculate-polynomial-subject-to
    (value :at 0 :equals 0)
    (derivative :at 0 :equals 0)
    (nth-derivative 2 :at 0 :equals 0)
    (value :at 1 :equals 1)
    (derivative :at 1 :equals 0)
    (nth-derivative 2 :at 1 :equals 0)
    (value :at 1/2 :equals 3/4))

That’s all done now (polynomials.lisp). So, for the record, the above is: 26x^3 - 63x^4 + 54x^5 - 16x^6. That is still not quite the polynomial I want for this application, but it’s close. A few minutes of Lisp saved me hours of whiteboard work.

Updates In Email

Email:

l