10

Assuming I have an array of doubles, what's a good algorithm to sample this series using Akima interpolation? I'm too stupid to translate that mathematical description into code.

// values is an array of doubles
// idx is the index of the left-hand value for the current interpolation
// t is the normalized parameter between values[idx] and values[idx+1]
// Don't worry about array bounds, I'll handle that separately.
public double InterpolateAkima(double[] values, int idx, double t)
{
  ...?
}
David Rutten
  • 4,716
  • 6
  • 43
  • 72
  • 3
    It looks like a lot of work that nobody will just code up for you. It looks quite straight forward, but some good hours of coding to get it done. Don't hesitate to ask if there is a specific thing you don't understand. – Albin Sunnanbo Aug 17 '10 at 19:14
  • @Albin, fair enough I suppose. Cubic interpolation is like 10 lines of code, I was hoping all this math could be condensed down to maybe 20 lines... – David Rutten Aug 17 '10 at 19:50

2 Answers2

28

Repost and expansion on my answer to another SO question that was closed as a duplicate of this question - as suggested by a comment on that question.

Akima's original paper: ``A new method of interpolation and smooth curve fitting based on local procedures'', Journal of ACM 17, 4 (1970), 589-602

http://www.leg.ufpr.br/lib/exe/fetch.php/wiki:internas:biblioteca:akima.pdf

C implementation

https://github.com/ampl/gsl/blob/master/interpolation/akima.c

C# implementation

https://gist.github.com/dreikanter/3526685

Delphi implementation (see procedure BuildAkimaSpline in delphi/src/spline3.pas)

http://www.alglib.net/translator/re/alglib-2.6.0.delphi.zip

Akima's Fortran 66 implementation

http://cran.r-project.org/web/packages/akima/

Fortran 90 implementation

http://miyoshi.googlecode.com/svn-history/r72/trunk/common/common.f90

Java implementation

https://commons.apache.org/proper/commons-math/jacoco/org.apache.commons.math3.analysis.interpolation/AkimaSplineInterpolator.java.html

Lisp implementation "for AutoCAD 2d-Polylines"

http://autocad.xarch.at/code/candido/akima.lsp

Matlab implementation

http://www.mathworks.se/matlabcentral/fileexchange/1814-akima-interpolation

Pascal implementation (program description)

http://jean-pierre.moreau.pagesperso-orange.fr/Pascal/akima_pas.txt

Python implementation

http://www.lfd.uci.edu/~gohlke/code/akima.py.html

VB6 implementation (see subroutine BuildAkimaSpline in vb6/src/spline3.bas)

http://www.alglib.net/translator/re/alglib-2.6.0.vb6.zip

http://www.koders.com/cpp/fid1393B9D668316C1700966643DE0609660B9CB13A.aspx?s=%22Brian+Smith%22

Community
  • 1
  • 1
Handcraftsman
  • 6,863
  • 2
  • 40
  • 33
  • In addition: [Mathematica implementation by Jens-Peer Kuska](https://groups.google.com/d/msg/comp.soft-sys.math.mathematica/XAWwuMCV_8w/FZDMf3Pgsz0J). – Alexey Popkov Jun 21 '11 at 23:08
  • Also alglib (mentioned only under VB6 and delphi) has C++, C#, python and other implementations as well. – Dan May 09 '13 at 09:06
  • Another C implemenation (GSL): https://www.gnu.org/software/gsl/manual/html_node/Interpolation-Types.html#Interpolation-Types – alfC Aug 28 '14 at 06:41
  • 1
    @CoolMind I found replacements for the broken links where possible. – Handcraftsman May 05 '16 at 15:21
  • 1
    @Handcraftsman Please add my TypeScript (JavaScript) implementation: [http://www.source-code.biz/snippets/typescript/akima](http://www.source-code.biz/snippets/typescript/akima) – Christian d'Heureuse Aug 29 '16 at 16:41
  • C implementation link is wrong and must be fixed to point to exactly what it's text says: https://github.com/ampl/gsl/blob/master/interpolation/akima.c (and not some debian package lol). The C# link also points to 404 but the link text is correct : https://gist.github.com/dreikanter/3526685 – bliako Jul 28 '19 at 11:33
7

Got some hits on google code search but this isn't an area I know much about. The first result is for Math.NET which may be of some interest.

Kris
  • 7,110
  • 2
  • 24
  • 26