Created
October 12, 2023 10:35
-
-
Save stla/706af2eaae5419f66765343e3fde06e8 to your computer and use it in GitHub Desktop.
Barth sextic with Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MarchingCubes | |
import Meshes | |
using MeshViz | |
using GLMakie | |
using Makie | |
using Printf | |
# isosurface function f=0 | |
phi = (1 + sqrt(5)) / 2 | |
function f(x, y, z) | |
if x*x + y*y + z*z > 3 # clip the mesh to the ball of radius sqrt(3) | |
return 1000.0 | |
end | |
- 4 * (phi^2*x^2 - y^2) * (phi^2*y^2 - z^2) * (phi^2*z^2 - x^2) + | |
(1 + 2*phi) * (x^2 + y^2 + z^2 - 1)^2 | |
end | |
# make the isosurface | |
n = 200 | |
voxel = zeros(Float32, n, n, n) | |
rg = LinRange{Float32,Int32}(-1.8, 1.8, n) | |
coords = convert(Vector{Float32}, collect(rg)) | |
for k in 1:n, j in 1:n, i in 1:n | |
voxel[i, j, k] = f(rg[i], rg[j], rg[k]) | |
end | |
mc = MC(voxel, Int32; x = coords, y = coords, z = coords) | |
march(mc, Float32(0)) | |
mesh = MarchingCubes.makemesh(Meshes, mc) | |
println("marching cubes done") | |
function drawBS() | |
alpha_ = LinRange(0, 2*pi, 181)[1:180] | |
for i in 1:180 | |
sphere = Meshes.discretize(Meshes.Sphere((0, 0, 0), 1.8)) | |
fig, ax, plt = MeshViz.viz( | |
sphere; alpha = 0 # invisible bounding sphere | |
) | |
ax.show_axis = false | |
MeshViz.viz!(mesh; color = :purple) | |
Makie.scale!(ax.scene, 1.8, 1.8, 1.8) | |
Makie.rotate!(ax.scene, Meshes.Vec3f(0, 0, 1), alpha_[i]) | |
png = @sprintf "zzpic%03d.png" i | |
Makie.save(png, fig) | |
end | |
end |
Author
stla
commented
Oct 12, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment