Piecewise Linear Integer Curve Interpolation in C#/Unity3D

Given 3 or more numbers or vectors, how do I interpolate between them based on a percentage?

simple example for scalar float objects using piecewise linear interpolation:

int n=3;   // number of your objects
float x[n]={ 0.5,2.0,10.0 }; // your objects

float get_object(float t) // linearly interpolate objects x[] based in parameter t = <0,1>, return value must be the same type as your objects
{
int ix;
float x0,x1; // the same type as your objects
// get segment ix and parameter t
t*=n; ix=floor(t); t-=ix;
// get closest known points x0,x1
x0=x[ix]; ix++;
if (ix<n) x1=x[ix]; else return x0;
// interpolate
return x0+(x1-x0)*t;
}

so if t=0 it returns first object in the x[] if it is t=1 is returns last and anything in between is linearly interpolated ... The idea is just to multiply our t by number of segments or point (depend on how you handle edge cases) which integer part of the result will give us index of closest 2 objects to our wanted one and then the fractional part of multiplied t will give us directly interpolation parameter in range <0,1> between the two closest points...

In case you objects are not with the same weight or are not uniformly sampled then you need to add interpolation with weights or use higher order polynomial (quadratic,cubic,...).

You can use this for "any" type T of objects you just have to implement operations T+T , T-T and T*float if they are not present.

Real time optimization of sensor data to reduce log file size by omiting entries

The algorithm category could be "Line Simplification algorithms" or "downsampling"/ "data compression" algorithms:

Line Simplification algorithms

An example would be the "Ramer–Douglas–Peucker algorithm" / "iterative end-point fit algorithm" and "split-and-merge algorithm".

A C# implemententation:A-Csharp-Implementation-of-Douglas-Peucker-Line-Ap.

Some can be used for streaming data, such as Streaming Algorithms for Line Simplification.

History of research here: Curve Simplification Turk

Downsampling/ "data compression" algorithms

Question already answered here: downsampling-excessively-sampled-curves



Related Topics



Leave a reply



Submit