Skip to content

Commit

Permalink
Updated even sampling demos
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Mattheus-Moerman committed Jul 9, 2024
1 parent ca5d77e commit 376b345
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 33 deletions.
44 changes: 28 additions & 16 deletions examples/demo_evenly_sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ 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]
testCase = 2

# Define input curve
if testCase == 1
n = 5
t = range(0,2π-2π/n,n)
V = [GeometryBasics.Point{3, Float64}(3.0*cos(tt),3.0*sin(tt),0.0) for tt t]
elseif testCase == 2
n = 4*7+4
rFun(t) = sin(4*t)+2
V = circlepoints(rFun,n)
end

# Evenly sample curve
n = 50; # Number of points for spline
Expand All @@ -19,22 +25,28 @@ Vi2, S = evenly_sample(V, n; niter = 10, close_loop = true) # Returns points and


# Visualization

markersize1 = 10
markersize2 = 15
linewidth = 2

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)
hp1 = scatter!(ax1, V,markersize=markersize2,color=:red)
hp2 = lines!(ax1, V,linewidth=linewidth,color=:red)

ax2 = Axis3(fig[1, 2],aspect = :data,azimuth=-pi/2,elevation=pi/2, title="evenly sampled")
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)
hp1 = scatter!(ax2, V,markersize=markersize2,color=:red)
hp2 = lines!(ax2, V,linewidth=linewidth,color=:red)
hp3 = scatter!(ax2, Vi1,markersize=markersize1,color=:black)
hp4 = lines!(ax2, Vi1,linewidth=linewidth,color=:black)

ax3 = Axis3(fig[1, 3],aspect = :data,azimuth=-pi/2,elevation=pi/2, title="evenly sampled, 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)
hp1 = scatter!(ax3, V,markersize=markersize2,color=:red)
hp2 = lines!(ax3, V,linewidth=linewidth,color=:red)
hp3 = scatter!(ax3, Vi2,markersize=markersize1,color=:black)
hp4 = lines!(ax3, Vi2,linewidth=linewidth,color=:black)

fig

46 changes: 29 additions & 17 deletions examples/demo_evenly_space.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,51 @@ using Comodo
using GeometryBasics
using GLMakie

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

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

# Define input curve
if testCase == 1
n = 5
t = range(0,2π-2π/n,n)
V = [GeometryBasics.Point{3, Float64}(3.0*cos(tt),3.0*sin(tt),0.0) for tt t]
elseif testCase == 2
n = 4*7+4
rFun(t) = sin(4*t)+2
V = circlepoints(rFun,n)
end

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
n = 25; # 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

markersize1 = 10
markersize2 = 15
linewidth = 2

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)
hp1 = scatter!(ax1, V,markersize=markersize2,color=:red)
hp2 = lines!(ax1, V,linewidth=linewidth,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)
hp1 = scatter!(ax2, V,markersize=markersize2,color=:red)
hp2 = lines!(ax2, V,linewidth=linewidth,color=:red)
hp3 = scatter!(ax2, Vi1,markersize=markersize1,color=:black)
hp4 = lines!(ax2, Vi1,linewidth=linewidth,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)
hp1 = scatter!(ax3, V,markersize=markersize2,color=:red)
hp2 = lines!(ax3, V,linewidth=linewidth,color=:red)
hp3 = scatter!(ax3, Vi2,markersize=markersize1,color=:black)
hp4 = lines!(ax3, Vi2,linewidth=linewidth,color=:black)

fig

0 comments on commit 376b345

Please sign in to comment.