Skip to content

Commit

Permalink
Added close_curve option to evenly_space
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Mattheus-Moerman committed Jul 8, 2024
1 parent 6761df6 commit ce1c719
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
40 changes: 40 additions & 0 deletions examples/demo_evenly_space.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Comodo
using GeometryBasics
using GLMakie

# This demo shows how to evenly sample a curve using spline interpolations.

# Define raw curve
n = 5
t = range(0,2π-2π/n,n)
# t = range(0,2π,n)

V = [GeometryBasics.Point{3, Float64}(3.0*cos(tt),3.0*sin(tt),0.0) for tt t]

# Evenly sample curve
n = 50; # Number of points for spline
Vi1 = evenly_space(V, 0.3; niter = 10, close_loop = false) # Returns points and spline interpolation object

Vi2 = evenly_space(V, 0.3; niter = 10, close_loop = true) # Returns points and spline interpolation object


# Visualization
fig = Figure(size = (1200,500))

ax1 = Axis3(fig[1, 1],aspect = :data,azimuth=-pi/2,elevation=pi/2, title="Input")
hp1 = scatter!(ax1, V,markersize=25,color=:red)
hp2 = lines!(ax1, V,linewidth=3,color=:red)

ax2 = Axis3(fig[1, 2],aspect = :data,azimuth=-pi/2,elevation=pi/2, title="evenly spaced")
hp1 = scatter!(ax2, V,markersize=25,color=:red)
hp2 = lines!(ax2, V,linewidth=3,color=:red)
hp3 = scatter!(ax2, Vi1,markersize=15,color=:black)
hp4 = lines!(ax2, Vi1,linewidth=3,color=:black)

ax3 = Axis3(fig[1, 3],aspect = :data,azimuth=-pi/2,elevation=pi/2, title="evenly spaced, closed")
hp1 = scatter!(ax3, V,markersize=25,color=:red)
hp2 = lines!(ax3, V,linewidth=3,color=:red)
hp3 = scatter!(ax3, Vi2,markersize=15,color=:black)
hp4 = lines!(ax3, Vi2,linewidth=3,color=:black)

fig
6 changes: 3 additions & 3 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3526,12 +3526,12 @@ function integrate_segment_(dS,l1,l2,rtol)
return segment_length
end

function evenly_space(V::Vector{Point{ND,TV}}, pointSpacing=nothing; rtol = 1e-8, niter = 1) where ND where TV<:Real
function evenly_space(V::Vector{Point{ND,TV}}, pointSpacing=nothing; rtol = 1e-8, niter = 1, close_loop=false) where ND where TV<:Real
if isnothing(pointSpacing)
pointSpacing = pointspacingmean(V)
end
n = ceil(Int64,maximum(curve_length(V))/pointSpacing)
Vn,_ = evenly_sample(V,n; rtol=rtol, niter=niter)
n = ceil(Int64,maximum(curve_length(V; close_loop=close_loop))/pointSpacing)
Vn,_ = evenly_sample(V,n; rtol=rtol, niter=niter, close_loop=close_loop)
return Vn
end

Expand Down
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4126,8 +4126,16 @@ end
pointSpacing = pointspacingmean(V)
Vn = evenly_space(V,pointSpacing)
@test isapprox(pointspacingmean(Vn),pointSpacing,atol=eps_level)
end

r = 1000
nc = 1000
V = circlepoints(r,nc)
pointSpacing = 1
Vn = evenly_space(V,pointSpacing; close_loop = true)
@test isapprox(pointspacingmean(Vn),pointSpacing, atol=eps_level)
@test length(Vn) == ceil(2*pi*r/pointSpacing)

end

@testset "invert_faces" begin
# Single face
Expand Down

0 comments on commit ce1c719

Please sign in to comment.