Interpolate a 3D curve?

Hi everyone, I know this must be very simple using Interpolations.jl but I can’t get it to work. I have a 3D curve in an array (example bellow) and I need to have 10 times more points. Linear or Bspline interpolation between the points are OK.
Any idea?
Thanks in advance

rayo=[-67 0.00 200.0
-67 0.09 210.0
-67 2.06 410.0
-67 6.04 660.0
-67 14.26 778.8
-67 22.48 660.0
-67 26.45 410.0
-67 28.43 210.0
-67 28.52 200.0
-67 29.82 35.0
-67 29.91 20.0
-67 30.00 0.0]

julia> itp=interpolate(rayo,BSpline(Linear()))
12×3 interpolate(::Matrix{Float64}, BSpline(Linear())) with element type Float64:
 -67.0   0.0   200.0
 -67.0   0.09  210.0
 -67.0   2.06  410.0
 -67.0   6.04  660.0
 -67.0  14.26  778.8
 -67.0  22.48  660.0
 -67.0  26.45  410.0
 -67.0  28.43  210.0
 -67.0  28.52  200.0
 -67.0  29.82   35.0
 -67.0  29.91   20.0
 -67.0  30.0     0.0

julia> itp(range(1,12,length=120),1:3)
1 Like

Works great! Thanks!

Dierckx.jl parametric splines interpolation is perfect for this problem:

using Dierckx
N = size(rayo,1)
spl = ParametricSpline(1:N, rayo')  # adjoint to have data series along matrix rows
tfine = LinRange(1, N, 10*N)  # interpolates with 10x more points
xyz = evaluate(spl,tfine)'

3D_points_Dierckx_Parametric_Interpolation

3 Likes

Ok, I will admit that one is exactly what I wanted

1 Like

I am getting a bit of back-and-forth with the interpolation, any way to get rid of it?

Are you referring to the tiny variation around the constant -67.0 coordinate?

julia> extrema(xyz[:,1])
(-67.00000000000003, -66.99999999999997)

To tame the plots use the xlims keyword.

More in the Y coordinate… it makes some “Z” that I can’t have. I know it is usual with splines… but I wonder if they can be avoided.

Could you post a graph of what exactly you mean to avoid misinterpretation?
If you refer to the “overshooting” of the interpolating parametric splines in the plot below of the y coordinates versus point number, this can be overcome by using the smoothing option that does not pass exactly at the points:

spl2 = ParametricSpline(1:N, rayo', s=2000)  # define smoothing error s, data dependent

Result for y-coordinate:

1 Like