Last active
October 12, 2023 17:13
-
-
Save stla/50e904e3a974a801659d495efa565adf to your computer and use it in GitHub Desktop.
Hopf torus with Julia, circle by circle
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 Meshes | |
using MeshViz | |
using GLMakie | |
function HopfTorus(u, nlobes, A) | |
t = [0, pi / 2, pi] | |
cos_v = cos.(t) | |
sin_v = sin.(t) | |
B = pi / 2 - (pi / 2 - A) * cos(u * nlobes) | |
C = u + A * sin(2 * u * nlobes) | |
y1 = 1 + cos(B) | |
y23 = sin(B) .* [cos(C), sin(C)] | |
y2 = y23[1] | |
y3 = y23[2] | |
x1 = y3 .* cos_v + y2 .* sin_v | |
x2 = y2 .* cos_v - y3 .* sin_v | |
x3 = y1 .* sin_v | |
x4 = y1 .* cos_v | |
yden = sqrt(2 * y1) | |
m = hcat(x1 ./ (yden .- x4), x3 ./ (yden .- x4), x2 ./ (yden .- x4)) | |
return eachrow(m) | |
end | |
function drawHT(alpha1, alpha2) | |
sphere = Meshes.discretize(Meshes.Sphere((0, 0, 0), 1)) | |
fig, ax, plt = MeshViz.viz( # invisible bounding sphere | |
sphere; alpha = 0 | |
) | |
ax.show_axis = false | |
u_ = LinRange(0, 2 * pi, 210) | |
for i = 1:210 | |
p1, p2, p3 = HopfTorus(u_[i], 3, 0.44) | |
torus = Torus( | |
Meshes.Point(tuple(p1...)), | |
Meshes.Point(tuple(p2...)), | |
Meshes.Point(tuple(p3...)), | |
0.3 | |
) | |
mesh = discretize(torus) | |
MeshViz.viz!(mesh; color = :darkred) | |
end | |
Makie.scale!(ax.scene, 1.65, 1.65, 1.65) | |
Makie.rotate!(fig.scene, Meshes.Vec3f(1, 0, 0), alpha1) | |
Makie.rotate!(ax.scene, Meshes.Vec3f(0, 0, 1), alpha2) | |
Makie.save("HopfTorus_CbyC.png", fig) | |
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