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
Why Can't I Retrieve an Item from a Hashset Without Enumeration
Entity Framework Specification Pattern Implementation
C# - Elegant Way of Partitioning a List
How to Get the Selected Item of a Combo Box to a String Variable in C#
Why Is ASP.NET Identity Identitydbcontext a Black-Box
Writing File to Web Server - ASP.NET
Assemblytitle' Attribute in the .Net Framework
Get List of Certificates from the Certificate Store in C#
How to Set PDF Paragraph or Font Line-Height with Itextsharp
ASP.NET Core MVC - Client-Side Validation for Custom Attribute
Navigation Property Without Declaring Foreign Key
How to Add a Custom View Dynamically to a View in Visual Studio for MAC C#
C# Async/Await Progress Event on Task<> Object