2

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?

MarcoB
  • 67,153
  • 18
  • 91
  • 189
murray
  • 11,888
  • 2
  • 26
  • 50
  • 1
  • @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 (https://community.wolfram.com/groups/-/m/t/1636443) using currently built-in, high-level functions. – murray Mar 21 '19 at 01: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.'s missing motivation Mar 21 '19 at 01:36
  • 2
    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 '19 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 '19 at 14:23
  • @J.M.isslightlypensive: In the post you cite, you say, "there are now better methods" than your re-implementation of SplineFit. Exactly what are those methods? All I need is an implementation of SplineFit[{pts}, Cubic. I don't directly see how to use Interpolation (with option Method -> "Spline"). And I don't see how to exploit the several currently built-in spline-related functions, as they merely use the given points as control points rather than actually pass the (piecewise) spline through those points. – murray Mar 23 '19 at 14:05
  • "All I need is an implementation of SplineFit[{pts}, Cubic]" - and that's what's in that answer. I only added the caveat that it isn't the best thing to use anymore. (See e.g. this answer for one of the "better methods".) – J. M.'s missing motivation Mar 23 '19 at 14:09

1 Answers1

2

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}
Greg Hurst
  • 35,921
  • 1
  • 90
  • 136