Skip to content

Interpolation Module #459

@swharden

Description

@swharden

ScottPlot could benefit from an interpolation module.

Interpolation can take a small number of X/Y values and create smooth curves from them. There are different interpolation algorithms, with linear, cosine, and cubic being some of the most common.

This website has some nice simple descriptions: http://paulbourke.net/miscellaneous/interpolation/

If implemented, interpolations may help in dynamic colormap generation. #458

There are more advanced forms of interpolation (https://en.wikipedia.org/wiki/Interpolation) so a well-designed interpolation module would be easy to extend.

Code Example

Here's some code that demonstrates the idea using cosine interpolation.

image

formsPlot1.plt.Clear();

int[] rXs = { 0, 50, 100, 150, 200, 255 };
int[] rYs = { 123, 222, 18, 76, 241, 164 };

double[] rInterpolated = new double[255];
for (int splineIndex = 0; splineIndex < rXs.Length - 1; splineIndex++)
{
    int x1 = rXs[splineIndex];
    int x2 = rXs[splineIndex + 1];
    int y1 = rYs[splineIndex];
    int y2 = rYs[splineIndex + 1];

    int distance = x2 - x1;
    for (int i = 0; i < distance; i++)
    {
        double muLinear = (double)i / distance;
        double muCos = (1 - Math.Cos(muLinear * Math.PI)) / 2;

        double mu = muCos;
        rInterpolated[x1 + i] = (y1 * (1 - mu) + y2 * mu);
    }
}

formsPlot1.plt.PlotScatter(
    ScottPlot.Tools.DoubleArray(rXs),
    ScottPlot.Tools.DoubleArray(rYs),
    Color.Red, 0);

formsPlot1.plt.PlotSignal(rInterpolated);

formsPlot1.plt.Axis(0, 255, 0, 255);
formsPlot1.Render();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions