The code provided would not run in my machine “as is”. The edited code below runs. Need to set alphahull in mesh3d.
using Plots, PlotlyJS, QuadGK, Meshing, StaticArrays
plotly()
function unknotintegralfunction(a,b,c,t)
1/(sqrt( (a - cos(t))^2 + (b - sin(t))^2 + c^2 ))
end
function unknotpotential(a,b,c,A)
ans0, err = quadgk(t->unknotintegralfunction(a,b,c,t),0,2π,order=quadorder)
A[floor(Int,(10*a+21)),floor(Int,(10*b+21)),floor(Int,(10*c+21))] = ans0
return [a,b,c,ans0,err]
end
inflateunknot(f,N,p,A) = [f(x,y,z,A) for x in -N:p:N, y in -N:p:N, z in -N:p:N if z ≠ 0 || (x*x +y*y)≠ 1 ]
quadorder = 20
A = zeros(41,41,41)
ans = inflateunknot(unknotpotential,2,0.1,A)
c = A[20,20,20] + 0.5
points,surfaces = isosurface(A,MarchingCubes(iso=c), origin = SVector(1,1,1), widths = SVector(4.0,4.0,4.0))
scatter([a for (a,_,_) in points],[b for (_,b,_) in points], [c for (_,_,c) in points] )
PlotlyJS.plot(
PlotlyJS.mesh3d(
x = [a[1] for a in points],
y = [a[2] for a in points],
z = [a[3] for a in points],
alphahull = 5
)
)
