dtech
dtech

Reputation: 49289

An approach towards achieving non-linear interpolation?

I need to implement a method for non-linear interpolation between values, ease-in, ease-out, general easing curves as well as user defined curves.

I have a basic idea of how to do this - but I am not sure if it will be the most efficient solution. My idea is basically as follows:

Use a 2D cubic, quadratic or n-th order Bezier curve to control the interpolation. Traverse through the curve linearly to get the non-linear Y component, and use that to value to feed a simple linear interpolation method:

value = v1 + (v2 - v1) * t;

Where t is the non-linear Y component of the control curve.

This allows for custom, user defined methods for interpolation, but it comes at a cost, the cost of one non-linear interpolation is equal to:

1 + 2 * (n-1)

total interpolations, where n is the order, or number of control points of the control curve.

I am NO MATHEMATICIAN, this is the best I could come up with, so my question is if there is a better solution?

EDIT: I am probably not explaining it right, I am not a native speaker, so here is something hopefully everyone will understand: control curve interpolation

Upvotes: 3

Views: 3120

Answers (1)

vhallac
vhallac

Reputation: 13907

From what I understand, your t is actually a family of functions fi(u), where both u, and fi(u) are between 0 and 1. If that is the case, it doesn't get any better than what you've already proposed.

It looks like you are worried about evaluating these fi(u) values during actual curve calculation. There is no avoiding the evaluation if you don't want to pre-calculate. If performance is a big issue and you don't need to be very precise, you can calculate tables of fi(uj) for as many uj values as you want (say 100 or 1000 discrete points between 0 and 1) for each of your curves, and when you need a value between your sampling points, do a simple linear interpolation of the two cached values around your desired point.

Upvotes: 4

Related Questions