       Re: sampling a spline

• To: mathgroup at smc.vnet.net
• Subject: [mg106082] Re: sampling a spline
• From: dh <dh at metrohm.com>
• Date: Fri, 1 Jan 2010 05:33:20 -0500 (EST)
• References: <hhhmdr\$o0g\$1@smc.vnet.net>

```Hi Charles,
as I undersatnd your question, you want to sample the spline at
equidistant points.
The reason this is not simple is that a spline is not a function, but
a graphics object. Therefore, operations that are defined for
functions do not work with a SplineFunction.
To obtain a equidistant sampling we may re-parametrize the spline with
the curve length.
Toward this aim, we describe the spline by an approximating numerical
function. Assume we have data and fit a spline:
d = RandomReal[1, {5, 2}]
sp = SplineFit[d, Cubic];
The spline is a vector function. We can approximate it ny a numerical
function by:
f1[t_?NumericQ] := sp[t][];
f2[t_?NumericQ] := sp[t][];
fun = Evaluate@{Evaluate@
FunctionInterpolation[f1[t], {t, 0, 4},
InterpolationOrder -> 4][#],
Evaluate@
FunctionInterpolation[f2[t], {t, 0, 4},
InterpolationOrder -> 4][#]} &;
Note that we need to increase the default order to obtain a reasonable
accuracy.
We can now calculate the length of the tangent in the original
parametrisation. Using this we can get the curve length as a function
of the original parameter:
ltan = FunctionInterpolation[Norm[fun'[tt]], {tt, 0, 4}]
s = FunctionInterpolation[ Integrate[ltan[ttt], {ttt, 0, tt}], {tt, 0,
4}]
To obtain the original parameter as a fzunction of the curve length,
we need to invert this function. W may do this using the fact that the
derivative of the inverse function  is the inverse of the original
function:
param = par /.  NDSolve[{par'[x] == 1/ltan[par[x]], par == 0},
par, {x, 0, s}][]
This gives us the original parameter as a function of the curve
length.

Here is the whole example with a plot where the data points are black
and the equidistant points are red:
Needs["Splines`"];
d = RandomReal[1, {5, 2}]
sp = SplineFit[d, Cubic];

f1[t_?NumericQ] := sp[t][];
f2[t_?NumericQ] := sp[t][];
fun = Evaluate@{Evaluate@
FunctionInterpolation[f1[t], {t, 0, 4},
InterpolationOrder -> 4][#],
Evaluate@
FunctionInterpolation[f2[t], {t, 0, 4},
InterpolationOrder -> 4][#]} &;

ltan = FunctionInterpolation[Norm[fun'[tt]], {tt, 0, 4}]
s = FunctionInterpolation[
Integrate[ltan[ttt], {ttt, 0, tt}], {tt, 0, 4}]
param = par /.
NDSolve[{par'[x] == 1/ltan[par[x]], par == 0},
par, {x, 0, s}][]

ParametricPlot[fun[param[t]], {t, 0, s},
Epilog -> {Red,
Point[Table[sp[Min[4, Max[0, param[t]]]], {t, 0, s, s/100}]],
Black, Point[d]}]

Daniel

On 31 Dez., 09:12, "Hagwood, Charles R." <charles.hagw... at nist.gov>
wrote:
> How does one uniformly sample a spline gotten from the command SplineFit?
>
> Charles Hagwood

```

• Prev by Date: Re: Re: Weird localization bug!
• Next by Date: Re: Re: Re: algebraic numbers
• Previous by thread: Re: sampling a spline
• Next by thread: Re: Wrapping Begin["Context`"], ..., End[] into a function