Hello,
I have a problem with a 3D animation. This is a torus which reverses itself. The problem is that when it is reversed, it is ugly because the normals are not oriented as they should. How to solve this problem?
using Meshes
using MeshViz
using GLMakie
using Makie
using Printf
# parameterization of the Clifford torus
function Clifford(u, v)
[cos(u), sin(u), cos(v), sin(v)] / sqrt(2)
end
# a 4D rotation
function rotate4D(x, t)
cost = cos(t)
sint = sin(t)
[
-x[1]*sint + x[4]*cost,
x[2]*cost - x[3]*sint,
x[2]*sint + x[3]*cost,
-x[1]*cost - x[4]*sint
]
end
# modified stereographic projection
function stereog(p)
r = acos(p[4]) / pi / sqrt(1-p[4]*p[4])
(r*p[1], r*p[2], r*p[3])
end
# topology
nu = 300
nv = 300
topo = GridTopology((nv, nu), (true, true))
# subdivisions
u_ = LinRange(0, 2*pi, nu+1)[1:nu]
v_ = LinRange(0, 2*pi, nv+1)[1:nv]
# draw the Clifford torus
function drawCT(nplots, alpha1, alpha2)
t_ = LinRange(0, 2*pi, nplots+1)[1:nplots]
for i in 1:nplots
fig, ax, _ = viz( # invisible bounding box
Meshes.Box(Meshes.Point(-1, -1, -1), Meshes.Point(1, 1, 1));
alpha = 0
)
ax.show_axis = false
points = [
stereog(rotate4D(Clifford(u, v), t_[i]))
for u in u_ for v in v_
]
mesh = SimpleMesh(Meshes.Point.(points), topo)
viz!(mesh; color = :maroon1)
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)
png = @sprintf "zzpic%03d.png" i
Makie.save(png, fig)
end
end