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?

  • 1
    $\begingroup$ Have you seen this? $\endgroup$ – J. M. will be back soon Mar 21 at 1:08
  • $\begingroup$ @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. $\endgroup$ – murray Mar 21 at 1:23
  • $\begingroup$ 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? $\endgroup$ – J. M. will be back soon Mar 21 at 1:36
  • 2
    $\begingroup$ 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? $\endgroup$ – MarcoB Mar 21 at 13:57
  • $\begingroup$ @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. $\endgroup$ – murray Mar 21 at 14:23

It appears you can reparametrize a BezierFunction:

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

fit = SplineFit[rand, Bezier];

bf = BezierFunction[rand];

Table[Chop[fit[t] - bf[t/len]], {t, 0, len, .01}] // MinMax
{0, 0}
  • $\begingroup$ That covers the Bezier case; some additional work is needed for CompositeBezier. Cubic is covered by my previous answer, as noted in the comments. $\endgroup$ – J. M. will be back soon Mar 22 at 6:09
  • $\begingroup$ @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.) $\endgroup$ – murray Mar 22 at 14:50
  • $\begingroup$ @murray, this isn't my answer; my answer in the other thread doesn't use the package. $\endgroup$ – J. M. will be back soon Mar 22 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.