[SciPy-User] Arc length of parametric spline

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[SciPy-User] Arc length of parametric spline

Kenny Vermeers
Hi,

I have a curve given by x,y points and interpolated it using splines with parameter t. t is in [0-1] by default but I would like to remap this to [0-arclength]. My plan was to calculate the arc length analytically or numerically using the light blue highlighted formula in http://tutorial.math.lamar.edu/Classes/CalcII/ParaArcLength.aspx i.e. int_0to1(sqrt((dx/dt)^2 + (dy/dt)^2))dt

In order to do this I need the splines dx/dt and dy/dt,. I was going to do this as follows
tck, u = interpolate.splprep([x, y])
dspl = interpolate.splder(tck)
hoping to get dx/dt and dy/dt and then solving the integral. Unfortunately that doesn't work since splder doesn't seem to accept parametric splines. Do you have any suggestions on how to get the spline parameter from 0 to arclen?

Thanks!

Kenny




_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Arc length of parametric spline

Pauli Virtanen-3
Kenny Vermeers kirjoitti 11.05.2017 klo 12:12:
> In order to do this I need the splines dx/dt and dy/dt,. I was going to
> do this as follows
> tck, u = interpolate.splprep([x, y])
> dspl = interpolate.splder(tck)
> hoping to get dx/dt and dy/dt and then solving the integral.
> Unfortunately that doesn't work since splder doesn't seem to accept
> parametric splines. Do you have any suggestions on how to get the spline
> parameter from 0 to arclen?

You can grab the x(u) and y(u) splines from the output of splprep. It is
a bit ugly because splprep has a different padding convention than splrep.

t, c, k = tck
cx = np.concatenate([c[0], np.zeros(len(t) - len(c[0]))])
cy = np.concatenate([c[1], np.zeros(len(t) - len(c[1]))])
tck_x = (t, cx, k)
tck_y = (t, cy, k)
_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user