GithubHelp home page GithubHelp logo

loadfc / arduino-interpolation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from luisllamasbinaburo/arduino-interpolation

0.0 1.0 0.0 129 KB

Interpolation library for Arduino and similar

License: Apache License 2.0

C++ 100.00%

arduino-interpolation's Introduction

Arduino Interpolation Library

Arduino library that provides interpolation methods step, linear, smooth, catmull spline and constrained spline.

All methods recieves X-Values and Y-Values, the size of this arrays and the X point to interpolate, and return the estimated Y at the point X.

Modes

Step

Simple step interpolation. Estimated value is Yn-1 or Yn. The relative 'change point' int he interval (or threshold) is an optional parameter. 0.0 means change at the start of the interval, 1.0 at the and of the interval, and 0.5 in the mid point interval. Image

Linear

Linear interpolation. Adicional parameter controls the interpolation out of the provided X-Values arrays. Image

Smooth

Applies a cubic smooth step between value changes Image

Catmull spline

Typical Catmull spline interpolation Image

Constrained spline

A special kind of spline that doesn't overshoot Image

Example

#include "InterpolationLib.h"

const int numValues = 10;
double xValues[10] = {   5,  12,  30,  50,  60,  70,  74,  84,  92, 100 };
double yValues[10] = { 150, 200, 200, 200, 180, 100, 100, 150, 220, 320 };

void setup()
{
	while (!Serial) { ; }
	Serial.begin(115200);

	for (float xValue = 0; xValue <= 110; xValue += .25)
	{
	  Serial.print(Interpolation::Step(xValues, yValues, numValues, xValue, 0.0));
		Serial.print(',');
		Serial.print(Interpolation::Step(xValues, yValues, numValues, xValue, 0.5));
		Serial.print(',');
		Serial.print(Interpolation::Step(xValues, yValues, numValues, xValue, 1.0));
		Serial.print(',');
		Serial.print(Interpolation::SmoothStep(xValues, yValues, numValues, xValue));
		Serial.print(',');
		Serial.print(Interpolation::Linear(xValues, yValues, numValues, xValue, false));
		Serial.print(',');
		Serial.print(Interpolation::Linear(xValues, yValues, numValues, xValue, true));
		Serial.print(',');
		Serial.print(Interpolation::CatmullSpline(xValues, yValues, numValues, xValue));
		Serial.print(',');
		Serial.println(Interpolation::ConstrainedSpline(xValues, yValues, numValues, xValue));
	}
}

void loop()
{
}

Auxiliar tools

Aditional utils

Float map

A simple map function that uses templates, so it works with integer (like normal 'map' function), float, double, or any other comparable type.

Interpolation::Map<float>(2.0, 0.0, 10, 100, 200)

Range generator

A simple utility that generates static double arrays with fixed size, and values between 'min' and 'max'. Useful for fast generating homogeneously distributed X-values arrays to use as parameter in the interpolations methods.

double*  ptr = Range<size>::Generate(min, max);

arduino-interpolation's People

Contributors

luisllamasbinaburo avatar paraciel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.