Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Smooth curve interpolation based on local procedures for a multiple-valued curve
| ResourceFunction["AkimaSpline"][{x1,y1},{x2,y2},…}] represents an Akima-spline function defined by the data {xi, yi}. | 
Construct an Akima-spline curve using a list of data points:
| In[1]:= |  | 
| In[2]:= | ![f = ResourceFunction["AkimaSpline"][pts]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/10959aa778096505.png) | 
| Out[2]= |  | 
Apply the function to find a point on the curve:
| In[3]:= | ![f[0.5]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/56b9854646f81bba.png) | 
| Out[3]= |  | 
Plot the Akima-spline curve with the data points:
| In[4]:= | ![Show[ParametricPlot[f[t], {t, 0, 1}], ListPlot[pts, PlotStyle -> Red]]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/3ad1c2649c54e0d9.png) | 
| Out[4]= |  | 
Ordinate values can be repeated:
| In[5]:= |  | 
| In[6]:= | ![g = ResourceFunction["AkimaSpline"][pts];](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/5bfa4e89a78866d5.png) | 
Plot the Akima-spline curve with the data points:
| In[7]:= | ![Show[ParametricPlot[g[t], {t, 0, 1}], ListPlot[pts, PlotStyle -> Red]]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/1dd9c977e200b9e7.png) | 
| Out[7]= |  | 
| In[8]:= | ![pts = With[{n = 12}, N@Table[(1 + 1/4 (-1)^i) {Cos[(2 \[Pi] i)/n], Sin[(2 \[Pi] i)/n]}, {i, 0, n}]];](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/1bd0c1e1e7ebe728.png) | 
| In[9]:= | ![fp = ResourceFunction["AkimaSpline"][pts, PeriodicInterpolation -> True]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/1356912a030943a4.png) | 
| Out[9]= |  | 
Plot the Akima-spline curve with the data points:
| In[10]:= | ![Show[ParametricPlot[fp[t], {t, 0, 1}], ListPlot[pts, PlotStyle -> Red]]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/3c0f957b4a98f892.png) | 
| Out[10]= |  | 
Interpolate random data:
| In[11]:= | ![f = ResourceFunction["AkimaSpline"][r = RandomReal[1, {20, 2}]]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/3e707447e8c40557.png) | 
| Out[11]= |  | 
| In[12]:= | ![Show[ParametricPlot[f[t], {t, 0, 1}], ListPlot[r, PlotStyle -> Red]]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/1b3d00eeb941173a.png) | 
| Out[12]= |  | 
Sort the points into a traveling salesman tour:
| In[13]:= | ![tour = Last@FindShortestTour[r]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/5d77ceb3bcf6e685.png) | 
| Out[13]= |  | 
| In[14]:= | ![ft = ResourceFunction["AkimaSpline"][r[[tour]]]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/11d807a11d0b627f.png) | 
| Out[14]= |  | 
| In[15]:= | ![Show[ParametricPlot[ft[t], {t, 0, 1}], ListPlot[r, PlotStyle -> Red]]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/43d707c4ca39873d.png) | 
| Out[15]= |  | 
Interesting knot-like figures can be drawn:
| In[16]:= | ![input = {{1, 1}, {0, -0.5}, {-1, 1}, {0.5, 0}, {-1, -1}, {0, 0.5}, {1, -1}, {-0.5, 0}, {1, 1}};
ifun = ResourceFunction["AkimaSpline"][input, PeriodicInterpolation -> True];
ParametricPlot[ifun[z], {z, 0, 1}, Axes -> False, Frame -> True, AspectRatio -> 1, PlotRange -> All, Epilog -> {Red, PointSize[0.02], Point[input]}]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/376af787e9ed990f.png) | 
| Out[18]= |  | 
A “braided” Spikey:
| In[19]:= | ![spikeyData = Graphics[{
GraphicsComplex[{{0, 0}, {(Rational[
         5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[1, 2], Rational[
        1, 4] (-1 - 5^Rational[1, 2])}, {0, -(
         2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
         1, 2]}, {(
        Rational[1, 4] (1 + 5^Rational[1, 2])) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[
         1, 2], -((Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2]) (
          2 + Rational[1, 2] (1 + 5^Rational[1, 2])))^Rational[
         1, 2]}, {(
        Rational[1, 4] (-1 + 5^Rational[1, 2])) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[
         1, 2], -((Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2]) (
          2 + Rational[1, 2] (1 + 5^Rational[1, 2])))^Rational[
         1, 2]}, {(
         Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[
         1, 2] (1 + (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2]), (Rational[1, 4] (-1 - 5^Rational[1, 2])) (
        1 + (2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2])}, {0, -1 - (
        2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[1, 2]}, {(
        Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[
        1, 2], Rational[
        1, 4] (-1 + 5^Rational[1, 2])}, {((
         Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2]) (
         2 + Rational[1, 2] (-1 + 5^Rational[1, 2])))^Rational[
        1, 2], (Rational[1, 4] (1 - 5^Rational[1, 2])) (
         2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
         1, 2]}, {(
        Rational[1, 4] (1 + 5^Rational[1, 2])) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[1, 2], ((
         Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2]) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2])))^Rational[
        1, 2]}, {(2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[
        1, 2], 0}, {(
         Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[
         1, 2] (1 + (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2]), (Rational[1, 4] (-1 + 5^Rational[1, 2])) (
        1 + (2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2])}, {(
         Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[
         1, 2] (1 + (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2]), (Rational[1, 4] (1 - 5^Rational[1, 2])) (
        1 + (2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2])}, {0, 1}, {((Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2]) (
         2 + Rational[1, 2] (-1 + 5^Rational[1, 2])))^Rational[
        1, 2], (Rational[1, 4] (1 + 5^Rational[1, 2])) (
         2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
         1, 2]}, {(
        Rational[1, 4] (1 - 5^Rational[1, 2])) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[1, 2], ((
         Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2]) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2])))^Rational[
        1, 2]}, {(
        Rational[1, 4] (-1 + 5^Rational[1, 2])) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[1, 2], ((
         Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2]) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2])))^Rational[
        1, 2]}, {0, 1 + (2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
         1, 2]}, {(
         Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[
         1, 2] (1 + (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2]), (Rational[1, 4] (1 + 5^Rational[1, 2])) (
        1 + (2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2])}, {-(
         Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[
         1, 2], Rational[
        1, 4] (-1 + 5^Rational[1, 2])}, {-((
          Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2]) (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2])))^Rational[
         1, 2], (Rational[1, 4] (1 + 5^Rational[1, 2])) (
         2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
         1, 2]}, {-(
         2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[1, 2], 0}, {(Rational[1, 4] (-1 - 5^Rational[1, 2])) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[1, 2], ((
         Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2]) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2])))^Rational[
        1, 2]}, {(-(
          Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[
          1, 2]) (1 + (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2]), (Rational[1, 4] (-1 + 5^Rational[1, 2])) (
        1 + (2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2])}, {(-(
          Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[
          1, 2]) (1 + (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2]), (Rational[1, 4] (1 + 5^Rational[1, 2])) (
        1 + (2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2])}, {-(
         Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[
         1, 2], Rational[
        1, 4] (-1 - 5^Rational[
         1, 2])}, {-((
          Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2]) (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2])))^Rational[
         1, 2], (Rational[1, 4] (1 - 5^Rational[1, 2])) (
         2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
         1, 2]}, {(
        Rational[1, 4] (1 - 5^Rational[1, 2])) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[
         1, 2], -((Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2]) (
          2 + Rational[1, 2] (1 + 5^Rational[1, 2])))^Rational[
         1, 2]}, {(
        Rational[1, 4] (-1 - 5^Rational[1, 2])) (
         2 + Rational[1, 2] (1 + 5^Rational[1, 2]))^Rational[
         1, 2], -((Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2]) (
          2 + Rational[1, 2] (1 + 5^Rational[1, 2])))^Rational[
         1, 2]}, {(-(
          Rational[5, 8] + Rational[-1, 8] 5^Rational[1, 2])^Rational[
          1, 2]) (1 + (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2]), (Rational[1, 4] (-1 - 5^Rational[1, 2])) (
        1 + (2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2])}, {(-(
          Rational[5, 8] + Rational[1, 8] 5^Rational[1, 2])^Rational[
          1, 2]) (1 + (
          2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2]), (Rational[1, 4] (1 - 5^Rational[1, 2])) (
        1 + (2 + Rational[1, 2] (-1 + 5^Rational[1, 2]))^Rational[
          1, 2])}}, {
GrayLevel[0], {{
Line[{1, 2, 3, 26}], 
Line[{3, 7, 28}], 
Line[{2, 5, 7}], 
Line[{2, 4, 6, 5}], 
Line[{1, 8, 9, 2}], 
Line[{9, 13, 4}], 
Line[{8, 11, 13}], 
Line[{8, 10, 12, 11}], 
Line[{1, 14, 15, 8}], 
Line[{15, 19, 10}], 
Line[{14, 17, 19}], 
Line[{14, 16, 18, 17}], 
Line[{1, 20, 21, 14}], 
Line[{21, 25, 16}], 
Line[{20, 23, 25}], 
Line[{20, 22, 24, 23}], 
Line[{1, 26, 27, 20}], 
Line[{27, 31, 22}], 
Line[{26, 29, 31}], 
Line[{26, 28, 30, 29}]}}, Null}]}, AspectRatio -> Automatic, ImageSize -> Medium];](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/7f425c065fb5007e.png) | 
| In[20]:= | ![points = FirstCase[spikeyData, GraphicsComplex[p_, _] :> p, {}, \[Infinity]];
edges = UndirectedEdge @@@ Join @@ (Partition[#, 2, 1] &) /@ Cases[spikeyData, Line[p_] :> p, \[Infinity]];
gr = Graph[edges, ImageSize -> Small]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/5630c02002366407.png) | 
| Out[22]= |  | 
| In[23]:= | ![cycles = FindCycle[gr, {6}, All];
vertexLists = Function[cycle, With[{v = First /@ cycle}, Append[v, First@v]]] /@ cycles;
lists = With[{keyVertices = {3, 9, 15, 21, 27}}, Cases[Cases[vertexLists, {___, #, ___}], l_ /; FreeQ[l, Alternatives @@ DeleteCases[keyVertices, #]]] & /@
     keyVertices];](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/3d5683b535ec07f4.png) | 
| In[24]:= | ![curves = ResourceFunction["AkimaSpline"][N@points[[#]], PeriodicInterpolation -> True] & /@ Join @@ lists; ParametricPlot[
 Through[curves[u]], {u, 0, 1}, Axes -> False]](https://www.wolframcloud.com/obj/resourcesystem/images/560/56058e84-6431-4180-806e-081c7e4cb2ad/23baeea25c207c50.png) | 
| Out[24]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License