# Geogebra spline command in Mathematica

Spline(pts, order, Weight Function)

Creates a spline with given order through all points. The weight function says what should be the difference of t values for point $$P_i$$ and $$P_{(i+1)}$$ given their difference $$P_{(i+1)} - P_i = (x, y)$$. To get the spline you expect from "function" algorithm you should use abs(x) + 0*y, to get the GeoGebra's default spline you can use sqrt(x^2+y^2).

Its implementation may be here.

Is there a corresponding function in Mathematica? I checked the documentation of the Interpolation and BSplineFunction,
I don't know how to set the weight function to reproduce the result. Let's say I have points pts like this, I generated the corresponding curve in Geogebra, which I converted into Mathematica code.

pts={{0,0},{1,1},{2,-1},{3,2},{4,1}};

cond={t<0.17,t<0.44,t<0.83,True};

val={{-11.52t^3+6.16t,-125.22t^3+9.52t},
{2.14t^3-7.05t^2+7.37t-0.07,159.41t^3-146.79t^2+34.75t-1.45},
{12.42t^3-20.72t^2+13.44t-0.97,-108.17t^3+209.4t^2-123.29t+21.93},
{-19.62t^3+58.87t^2-52.48t+17.23,115.04t^3-345.13t^2+335.92t-104.83}};

f[t_]=Piecewise[Transpose[{val,cond}]]

Show[ParametricPlot[Join[{f[t]},val]//Evaluate,{t,0,1},PlotStyle->{Black,Dashed,Dashed,Dashed,Dashed}],
Graphics[{PointSize[Large],Point[pts]}],PlotRange->{{0,5},{-2,3}}]


• If you find out what kind of boundary constraints Geogebra uses, then you could try to use the weighting scheme shown in the answer below with the CubicSplineInterpolation resource function. See also Understanding Interpolation with Cubic Splines. Commented May 25, 2022 at 12:04
• @Marco's idea is a good one. I don't have time to write something detailed, but: pts = {{0, 0}, {1, 1}, {2, -1}, {3, 2}, {4, 1}}; tp = N[ResourceFunction["LeeInterpolatingNodes"][pts, 1]]; ResourceFunction["InterpolatingFunctionToPiecewise"][ResourceFunction["CubicSplineInterpolation"][Transpose[{tp, #}], "Natural"], t] & /@ Transpose[pts] // Expand and compare with what Geogebra does. Commented May 25, 2022 at 16:41

Your link documents the default weight function but it doesn't say which kind of boundary constraints are used to obtain a unique spline.

pts = {{0, 0}, {1, 1}, {2, -1}, {3, 2}, {4, 1}};

(* Geogebra default weight *)
ts = Prepend[Accumulate[N[Normalize[Norm /@ Differences[pts], Total]]], 0]
(* {0, 0.17190381, 0.44370759, 0.82809619, 1.} *)


To get a spline with these parameter values for the points you can use Interpolation, but the result still differs because the boundary is handled differently:

ParametricPlot[Interpolation[Thread[{ts, pts}], Method -> "Spline"][x] // Evaluate, {x, 0, 1}, AspectRatio -> 1]


• What is called the "default weight" here is more properly known as "chord-length parametrization". The parametrizeCurve[] function from here with the second argument set to 1 will do this. Commented May 25, 2022 at 16:35