# How to reproduce old SplineFit function?

Prior to version 8, Mathematica included a SplineFit function that could be used, for example, in the form:

dat = RandomReal[{}, {5,2}];
SplineFit[dat, Cubic]


(Prior to version 7, SplineFit was part of the separate standard add-on package Splines.)

How can one reproduce the result with the current version of Mathematica, now that SplineFit is gone?

• Have you seen this? – J. M. will be back soon Mar 21 at 1:08
• @J.M.isslightlypensive: No I had not seen that; this should help. It would still be very useful if I could somehow reproduce the behavior of SplineFit in my situation (community.wolfram.com/groups/-/m/t/1636443) using currently built-in, high-level functions. – murray Mar 21 at 1:23
• If it's for display/plotting rather than evaluation at a point, the function in my answer can be modified so that it directly produces a BSplineCurve[]; I suppose that's what you want? – J. M. will be back soon Mar 21 at 1:36
• SplineFit is not gone. I can still run Needs["Splines"]; dat = RandomReal[{}, {5, 2}]; SplineFit[dat, Cubic] and I get a functioning SplineFunction object. Why re-invent the wheel then? – MarcoB Mar 21 at 13:57
• @MarcoB: could be dangerous, for future stability, to rely on the Splines package, which is somewhat hidden in the current version. the docs, at page Spines/SplineFit says, "As of Version 7.9, some of the functionality of the Splines Package is now built into the Wolfram Language kernel". But it doesn't say just what substitutes for SplineFit. – murray Mar 21 at 14:23

## 1 Answer

It appears you can reparametrize a BezierFunction:

len = 20;
SeedRandom[111];
rand = RandomReal[{0, 1}, {len+1, 3}];

Needs["Splines"]
fit = SplineFit[rand, Bezier];

bf = BezierFunction[rand];

Table[Chop[fit[t] - bf[t/len]], {t, 0, len, .01}] // MinMax

{0, 0}

• That covers the Bezier case; some additional work is needed for CompositeBezier. Cubic is covered by my previous answer, as noted in the comments. – J. M. will be back soon Mar 22 at 6:09
• @J.M.isslightlypensive: But my object is to try to avoid using the Splines package version of SplineFit. (Or was that a type and you meant to use your splineFit in this answer.) – murray Mar 22 at 14:50
• @murray, this isn't my answer; my answer in the other thread doesn't use the package. – J. M. will be back soon Mar 22 at 14:51