Skip to content

Commit

Permalink
Updates to evenly sample functions and demos to allow for must points
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Mattheus-Moerman committed Jul 9, 2024
1 parent 376b345 commit 70e21d8
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 78 deletions.
26 changes: 26 additions & 0 deletions examples/demo_curve_length.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Comodo
using GeometryBasics
using GLMakie
using BSplineKit
using QuadGK: quadgk # For numerical integration
using LinearAlgebra

testCase = 2

# Define input curve
if testCase == 1
V = Point{3,Float64}[[0,0,0],[1.0,0,0],[1,1,0],[0,1,0]]
close_loop = false
c = 3
elseif testCase == 2
n = 250
r = 2*pi
V = [Point{3,Float64}(r*cos(t),r*sin(t),0.0) for t in range(0,2*pi,n)]
close_loop = true
c = 2*pi*r
end

L = curve_length(V; close_loop = close_loop)
d = last(L)

println("Max. length: " * string(d) * ", theoretical/true: " * string(c))
24 changes: 18 additions & 6 deletions examples/demo_evenly_sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,36 @@ using GLMakie

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

testCase = 2
testCase = 3

# 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]

# Evenly sample curve
n = 50; # Number of points for spline
Vi1 = evenly_sample(V, n; spline_order=4, close_loop = false) # Returns points and spline interpolation object
Vi2 = evenly_sample(V, n; close_loop = true) # Returns points and spline interpolation object
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
Vi1, S = evenly_sample(V, n; niter = 10, close_loop = false) # Returns points and spline interpolation object
# Evenly sample curve
n = 75; # Number of points for spline
Vi1 = evenly_sample(V, n; spline_order=4, close_loop = false, niter = 10) # Returns points and spline interpolation object
Vi2 = evenly_sample(V, n; spline_order=4, close_loop = true, niter = 10) # Returns points and spline interpolation object
elseif testCase == 3
V = batman(25; symmetric = true, dir=:acw)

# Evenly sample curve
n = 50; # Number of points for spline
Vi1 = evenly_sample(V, n; niter = 10, spline_order=4, close_loop = false) # Returns points and spline interpolation object
Vi2 = evenly_sample(V, n; niter = 10, spline_order=4, close_loop = true) # Returns points and spline interpolation object
end

Vi2, S = evenly_sample(V, n; niter = 10, close_loop = true) # Returns points and spline interpolation object


# Visualization
Expand Down
31 changes: 24 additions & 7 deletions examples/demo_evenly_space.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,45 @@ using GLMakie

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

testCase = 2
testCase = 1

# 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]

must_points = [1,2,3,4,5]

# Evenly sample curve
Vi1 = evenly_space(V, 0.65; close_loop = false, spline_order = 4) # Returns points and spline interpolation object
Vi2 = evenly_space(V, 0.65; close_loop = true, spline_order = 4,must_points = must_points) # Returns points and spline interpolation object
elseif testCase == 2
n = 4*7+4
rFun(t) = sin(4*t)+2
V = circlepoints(rFun,n)
end

must_points = [3,7,11,15,19,23,27,31]

# Evenly sample curve
Vi1 = evenly_space(V, 0.5; close_loop = false, niter=10, spline_order = 4) # Returns points and spline interpolation object
Vi2 = evenly_space(V, 0.3; close_loop = true, niter=10, spline_order = 4,must_points = must_points) # Returns points and spline interpolation object
elseif testCase == 3
V = batman(25; symmetric = true, dir=:acw)

# Evenly sample curve
n = 25; # Number of points for spline
Vi1 = evenly_space(V, 0.3; niter = 10, close_loop = false) # Returns points and spline interpolation object
must_points = [7,10,13,15,18,21]

Vi2 = evenly_space(V, 0.3; niter = 10, close_loop = true) # Returns points and spline interpolation object
# Evenly sample curve
Vi1 = evenly_space(V, 0.15; close_loop = false, niter=10, spline_order = 4) # Returns points and spline interpolation object
Vi2 = evenly_space(V, 0.1; close_loop = true, niter=10, spline_order = 4, must_points = must_points) # Returns points and spline interpolation object
end


# Visualization

markersize1 = 10
markersize2 = 15
markersize3 = 20

linewidth = 2

fig = Figure(size = (1200,500))
Expand All @@ -45,6 +59,9 @@ 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=markersize2,color=:red)
if !isnothing(must_points)
hp5 = scatter!(ax3, V[must_points],markersize=markersize3,color=:green)
end
hp2 = lines!(ax3, V,linewidth=linewidth,color=:red)
hp3 = scatter!(ax3, Vi2,markersize=markersize1,color=:black)
hp4 = lines!(ax3, Vi2,linewidth=linewidth,color=:black)
Expand Down
4 changes: 2 additions & 2 deletions examples/demo_filletcurve_extrude.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rMax = 0.5 #collect(range(0.5,5,length(V)))
n = 20
h =2.0
VC = filletcurve(V; rMax=rMax, constrain_method = :max, n=n, close_loop = close_loop, eps_level = 1e-6)
VC,_ = evenly_sample(VC,50; spline_order = 2)
VC = evenly_sample(VC,50; spline_order = 2)

Fe,Ve = extrudecurve(VC; extent=h, direction=:both, close_loop=false,face_type=:quad)

Expand Down Expand Up @@ -59,7 +59,7 @@ hSlider1 = Slider(fig[2, 1], range = stepRange1, startvalue = 0,linewidth=30)

on(hSlider1.value) do stepIndex1
VC = filletcurve(V; rMax=stepIndex1, constrain_method = :max, n=n, close_loop = close_loop, eps_level = 1e-6)
VC,_ = evenly_sample(VC,53; spline_order = 2)
VC = evenly_sample(VC,53; spline_order = 2)
indPlot = collect(1:length(VC))
if close_loop == true
push!(indPlot,1)
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_loftlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ height = 2.5
rFun(t) = r + 0.5.* sin(4.0*t)
V2 = circlepoints(rFun,nc;dir=:acw)
V2 = [GeometryBasics.Point{3, Float64}(v[1],v[2],height) for v V2]
V2,_ = evenly_sample(V2,nc)
V2 = evenly_sample(V2,nc)
## Loft from curve 1 to curve 2
num_steps = 11 # Uneven works best for "tri" face type
close_loop = true
Expand Down
8 changes: 4 additions & 4 deletions examples/demo_regiontrimesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ elseif testCase == 3
r = 1.0
rFun(t) = r + 0.5.*sin(6*t)
V = circlepoints(rFun,n; dir=:acw)
V,_ = evenly_sample(V, n)
V = evenly_sample(V, n)
pointSpacing = pointspacingmean(V)

VT = (V,)
Expand All @@ -41,17 +41,17 @@ elseif testCase == 4
rFun1(t) = 12.0 + 3.0.*sin(5*t)
n1 = 120
V1 = circlepoints(rFun1,n1)
V1,_ = evenly_sample(V1,n1)
V1 = evenly_sample(V1,n1)

rFun2(t) = 10.0 + 2.0.*sin(5*t)
n2 = 100
V2 = circlepoints(rFun2,n2)
V2,_ = evenly_sample(V2,n2)
V2 = evenly_sample(V2,n2)

rFun3(t) = 2.0 + 0.5 *sin(5*t)
n3 = 50
Vp = circlepoints(rFun3,n3)
Vp,_ = evenly_sample(Vp,n3)
Vp = evenly_sample(Vp,n3)

V3 = [Point{3,Float64}(v[1],v[2]+6,v[3]) for v in Vp]
V4 = [Point{3,Float64}(v[1]-5,v[2]+1,v[3]) for v in Vp]
Expand Down
6 changes: 3 additions & 3 deletions examples/demo_revolvecurve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if testCase == 1
nc = 15
t = range(0,2*π,nc)
Vc = [Point3{Float64}(2.0+tt,0.0,sin(tt)) for tt t]
Vc,_ = evenly_sample(Vc, nc)
Vc = evenly_sample(Vc, nc)
n = Vec{3, Float64}(0.0,0.0,1.0)
num_steps = 31
close_loop = false
Expand All @@ -22,7 +22,7 @@ elseif testCase == 2
nc = 15
t = range(0,2*π,nc)
Vc = [Point3{Float64}(2.0+tt,0.0,sin(tt)) for tt t]
Vc,_ = evenly_sample(Vc, nc)
Vc = evenly_sample(Vc, nc)
n = normalizevector(Vec{3, Float64}(0.0,-1.0,1.0))
num_steps = 31
close_loop = false
Expand All @@ -31,7 +31,7 @@ elseif testCase == 3
nc = 16
t = range(2.0*π-(2.0*π/nc),0,nc)
Vc = [Point3{Float64}(2.0+cos(tt),0.0,sin(tt)) for tt t]
Vc,_ = evenly_sample(Vc, nc)
Vc = evenly_sample(Vc, nc)
n = Vec{3, Float64}(0.0,0.0,1.0)
num_steps = 25
close_loop = true
Expand Down
26 changes: 13 additions & 13 deletions examples/demo_sweeploft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ if testCase == 1
P[4 ] = GeometryBasics.Point{3, Float64}( 1.0, 1.0, 1.0)
Vc = nbezier(P,nc) # Get Bezier fit points
Vc = [vc.*10 for vc in Vc]
Vc,Sc = evenly_sample(Vc, nc)
Vc = evenly_sample(Vc, nc)

# Define section curves
np = 50 # Number of section points
cFun(t) = 2.0 + 0.5.*sin(3*t)
V1 = circlepoints(cFun,np; dir=:acw)
V1,_ = evenly_sample(V1, np)
V1 = evenly_sample(V1, np)
Q = RotXYZ(0.0,0.5*π,0.0) # Define a rotation tensor using Euler angles
V1 = [Q*v for v V1] # Rotate the coordinates

cFun(t) = 2.0 + 0.5*sin(3*t)
V2 = circlepoints(cFun,np; dir=:acw)
V2,_ = evenly_sample(V2, np)
V2 = evenly_sample(V2, np)
V2 = [v2 .+ Vc[end] for v2 V2]
elseif testCase == 2
# Define guide curve
Expand All @@ -41,19 +41,19 @@ elseif testCase == 2
P[4 ] = GeometryBasics.Point{3, Float64}( 3.0, 0.0, 0.0)
Vc = nbezier(P,nc) # Get Bezier fit points
Vc = [vc.*10 for vc in Vc]
Vc,Sc = evenly_sample(Vc, nc)
Vc = evenly_sample(Vc, nc)

# Define section curves
np = 35 # Number of section points
cFun(t) = 2.0 + 0.5.*sin(3*t)
V1 = circlepoints(cFun,np; dir=:acw)
V1,_ = evenly_sample(V1, np)
V1 = evenly_sample(V1, np)
Q = RotXYZ(0.0,0.5*π,0.0) # Define a rotation tensor using Euler angles
V1 = [(Q*v) .+ Vc[1] for v V1] # Rotate the coordinates

cFun(t) = 2.0 + 0.5*sin(3*t)
V2 = circlepoints(cFun,np; dir=:acw)
V2,_ = evenly_sample(V2, np)
V2 = evenly_sample(V2, np)
Q = RotXYZ(0.0,0.5*π,0.0) # Define a rotation tensor using Euler angles
V2 = [(Q*v) .+ Vc[end] for v V2]
elseif testCase == 3
Expand All @@ -68,7 +68,7 @@ elseif testCase == 3
# Section 1
cFun(t) = 1.5 + 0.5.*sin(3*t)
V1 = circlepoints(cFun,np; dir=:cw)
V1,_ = evenly_sample(V1, np)
V1 = evenly_sample(V1, np)
Q = RotXYZ(0.5*π,0.0,0.0) # Define a rotation tensor using Euler angles
V1 = [Q*v for v V1] # Rotate the coordinates

Expand All @@ -90,7 +90,7 @@ elseif testCase == 3
# Section 2
cFun(t) = 4 + 1.5*sin(5*t)
V2 = circlepoints(cFun,np; dir=:cw)
V2,_ = evenly_sample(V2, np)
V2 = evenly_sample(V2, np)
Q1 = RotXYZ(0.5*π,0.0,0.0) # Define a rotation tensor using Euler angles
Q2 = RotXYZ(0.0,-0.25*π,0.0) # Define a rotation tensor using Euler angles
Q = Q2*Q1
Expand Down Expand Up @@ -119,15 +119,15 @@ elseif testCase == 4
rc = rb/3
r = [rb + rc*sin(ff*tt) for tt in t]
Vc = [GeometryBasics.Point{3, Float64}(r[i]*cos(t[i]),r[i]*sin(t[i]),t[i]+rc*cos(ff*t[i])) for i in eachindex(t)]
Vc,_ = evenly_sample(Vc, nc)
Vc = evenly_sample(Vc, nc)

# Define section curves
np = 150 # Number of section points

# Section 1
cFun(t) = rc/3 + rc/5 .* sin(3*t)
V1 = circlepoints(cFun,np; dir=:cw)
V1,_ = evenly_sample(V1, np)
V1 = evenly_sample(V1, np)
Q = RotXYZ(0.5*π,0.0,0.0) # Define a rotation tensor using Euler angles
V1 = [Q*v for v V1] # Rotate the coordinates

Expand All @@ -149,7 +149,7 @@ elseif testCase == 4
# Section 2
cFun(t) = rc/4 + rc/6*sin(5*t)
V2 = circlepoints(cFun,np; dir=:cw)
V2,_ = evenly_sample(V2, np)
V2 = evenly_sample(V2, np)
Q1 = RotXYZ(0.5*π,0.0,0.0) # Define a rotation tensor using Euler angles
Q2 = RotXYZ(0.0,-0.25*π,0.0) # Define a rotation tensor using Euler angles
Q = Q2*Q1
Expand Down Expand Up @@ -181,7 +181,7 @@ elseif testCase ==5
# Section 1
cFun(t) = 3 + 0.25.*sin(3*t)
V1 = circlepoints(cFun,np; dir=:cw)
V1,_ = evenly_sample(V1, np)
V1 = evenly_sample(V1, np)
V1_ori = deepcopy(V1)

# Ensure section is orthogonal to guide curve
Expand All @@ -203,7 +203,7 @@ elseif testCase ==5
# Section 2
cFun(t) = 5 + 0.5*sin(5*t)
V2 = circlepoints(cFun,np; dir=:cw)
V2,_ = evenly_sample(V2, np)
V2 = evenly_sample(V2, np)
V2_ori = deepcopy(V2)

# Q1 = RotXYZ(0.5*π,0.0,0.0) # Define a rotation tensor using Euler angles
Expand Down
Loading

0 comments on commit 70e21d8

Please sign in to comment.