You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the above image, sampling the shown spline at equal intervals produces unequally spaced points. Is there a simple way to produce equally spaced points along a spline?
The text was updated successfully, but these errors were encountered:
BasicBSpline.jl does not provide API for that, but equally spaced points can be obtained using Newton's method:
using BasicBSpline
using Plots
using StaticArrays
using ForwardDiff
using LinearAlgebra
using FastGaussQuadrature
using Random
# Define B-spline curve
Random.seed!(2)
k =UniformKnotVector(1:12)
P =BSplineSpace{3}(k)
a = [rand(SVector{2}) for _ in1:dim(P)]
C =BSplineManifold(a,P)
# Plot non-equally spaced points on the curve
N =20
ps =C.(range(domain(P),length=N))
xs = [p[1] for p in ps]
ys = [p[2] for p in ps]
plot(C, aspectratio=:equal)
scatter!(xs, ys)
# Speed of the curvespeed(t) =norm(ForwardDiff.derivative(C,(t)))
# Parameter points on the curve
ts =collect(range(domain(P),length=N))
# Length between parameter points
ls =zeros(N-1)
# Update ts with iterationsfor _ in1:5for i in1:N-1
a, b = ts[i], ts[i+1]
nodes, weights =gausslegendre(20)
ls[i] =sum(speed.((nodes .+1) ./2.* (b-a) .+ a).*weights)*(b-a)/2end
L =sum(ls)
for i in2:N-1
d =sum(view(ls, 1:i-1)) -range(0,L,length=20)[i]
ts[i] -= d/speed(ts[i])
endend# Check lengths are equal
ls
# Plot the equally spaced points
ps =C.(ts)
xs = [p[1] for p in ps]
ys = [p[2] for p in ps]
plot(C, aspectratio=:equal)
scatter!(xs, ys)
In the above image, sampling the shown spline at equal intervals produces unequally spaced points. Is there a simple way to produce equally spaced points along a spline?
The text was updated successfully, but these errors were encountered: