Code Monkey home page Code Monkey logo

arduino-splines's Introduction

Arduino Splines

This is a simple library for differnent types of 1-D Splines, written for the arduino environment.

Usage

Checkout the code

git clone git://github.com/kerinin/arduino-splines.git ~/sketchbook/libraries/

Add the library header to your code

#include <spline.h>

There are currently 4 types of spline interpolation available:

  1. Degree 0: This generates a step function. Between any two points the spline evaluates to the previous point

  2. Degree 1: Linear interpolation. Between any two points the spline returns the value of a straight line connecting the bounding points

  3. Hermite: Uses a Hermite spline to interpolate between the points. This method requires that you specify an array of tangent values m as well as the point arrays x and y.

  4. Catmull: Uses a Catmull-Rom spline to interpolate between the points. This is an easy way to obtain smooth interpolation - you don't need to specify the tangent points.

Be aware that when using Catmull-Rom splines, the first and last points are not part of the spline - they are used to determine the tangency of the start and end of the spline. The spline itself starts at the second and second-to-last point.

For all splines, values requested outside the defined spline bounds will return the value of either the start or end point.

Using the library is fairly straightforward, simply pass it an array of points and use the value() function to interpolate between them. The spline points can be specified either when you instantiate the class or using the setPoints() and setDegree() functions.

double x[10] = {0,1,2,3,4,5,6,7,8,9};
double y[10] = {0,0,5,5,0,0,3,4,5,6};
doulbe m[10] = {0,.5,.5,.5.,.25,.25,.75,1,1,1}

Spline stepSpline(x,y,10,0);
Spline linearSpline(x,y,10,1);
Spline hermiteSpline(x,y,m,10);       // No neet to specify type since m passed
Spline catmullsSpline(x,y,10,Catmull);

stepSpline.value(5.5);    // => 0
linearSpline.value(5.5);  // => 1.5

Spline mySpline();
mySpline.setPoints(x,y);
mySpline.setDegree(1);

mySpline.value(5.5);      // => 1.5

arduino-splines's People

Contributors

kerinin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-splines's Issues

Catmull does not work for certain paths.

I'm developing an app where the user draws a path on the smartphone and an Arduino robot follows this path.

When I use Catmull interpolation on certain paths where the points wrap around. See the pictures.
I tested it on smaller data set and had the same issue.

I made these plots by printing the interpolated and actual path and importing them to Excel.
pic1
pic2

uncaught exceptions

you can use setpoints without _m
and set degree to Hermite

 x.setPoints( float x[], float y[], int numPoints );
 x.setDegree(Hermite);

Then calc will access _m[i], _m[i+1] which is not set.

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.