Closed Kevin-Mattheus-Moerman closed 8 months ago
It does look horrible! I think the problem is that, unlike in #85, here you're not parametrising the curve by the (approximate) arc length, which can lead to this kind of artefacts. I mean, this line:
T = range(0.0,1.0,length(V)) # Parameterise with unit total length
creates a uniform parametrisation, but your input points are strongly non-uniformly spaced.
If instead, following your initial example in #85, I do the following:
T = pushfirst!(cumsum(norm.(diff(V))),0.0) # Along curve distance from start
T ./= last(T) # normalise to [0, 1] range
then I get something which looks nice:
I hope this answers the question, I'm not sure I understood correctly what you're trying to do.
Right! Of course, my mistake. After I include that suggestion it all works. I was only trying to pass it something tricky and very non-uniform.
Updated solution here:
function evenly_sample(V,n)
m = length(V)
T = pushfirst!(cumsum(norm.(diff(V))),0.0) # Along curve distance from start
T ./= last(T) # normalise to [0, 1] range
S = interpolate(T, V, BSplineOrder(4),Natural()) # Create interpolator
dS = Derivative() * S # spline derivative
L = zeros(Float64,m) # Initialise spline length vector
for i ∈ 2:m
# Compute length of segment [i-1, i]
segment_length, _ = quadgk(T[i-1], T[i]; rtol = 1e-8) do t
norm(dS(t)) # integrate |S'(t)| in segment [i, i + 1]
end
L[i] = L[i - 1] + segment_length
end
L ./= last(L) # Normalise to 0-1 range
l = range(0.0,1.0,n) #Even allong curve distance
S = interpolate(L, V, BSplineOrder(4),Natural()) # Create interpolator
return S.(l),S # Evaluate interpolator at even distance increments
end
Thanks for your help!
@jipolanco
I tried to make a horribly irregularly sampled curve to test the even sampling approach discussed over at https://github.com/jipolanco/BSplineKit.jl/issues/85. Using the below code where I created some sorted unique random points from
0
up to2*pi
I unfortunately see unexpected squiggles in the spline. Am I doing something wrong?