Hello,
When I run the code above, I get:
ERROR: LoadError: MethodError: Meshes.Vec(::Vector{Float64}) is ambiguous.
However I only import (not using) Meshes, and there’s no Meshes.Vec
in my code. What should I do?
using Printf
import Makie
import Meshes
A = 4
B = 32
# construction of the vertices
duoprismVertices = Array{Float64,3}(undef, A, B, 4)
for i = 1:A
v1 = [cospi(2 * i / A), sinpi(2 * i / A)]
for j = 1:B
v2 = [cospi(2 * j / B), sinpi(2 * j / B)]
duoprismVertices[i, j, :] = vcat(v1, v2)
end
end
# construction of the edges
function dominates(c1, c2)
c2[1] > c1[1] || (c2[1] == c1[1] && c2[2] > c1[2])
end
function modulo(x, y)
((x % y) + y) % y
end
function getEdges()
edges = Array{Int64,3}(undef, 2, 2, 2 * A * B)
counter = 1
for i = 0:(A-1)
for j = 0:(B-1)
c1 = [i, j]
candidate = [i, modulo(j - 1, B)]
if dominates(c1, candidate)
edges[:, :, counter] = hcat(c1, candidate) .+ 1
counter = counter + 1
end
candidate = [i, modulo(j + 1, B)]
if dominates(c1, candidate)
edges[:, :, counter] = hcat(c1, candidate) .+ 1
counter = counter + 1
end
candidate = [modulo(i - 1, A), j]
if dominates(c1, candidate)
edges[:, :, counter] = hcat(c1, candidate) .+ 1
counter = counter + 1
end
candidate = [modulo(i + 1, A), j]
if dominates(c1, candidate)
edges[:, :, counter] = hcat(c1, candidate) .+ 1
counter = counter + 1
end
end
end
edges
end
edges = getEdges()
function rotate4d(alpha, beta, xi, vec)
a = cos(xi)
b = sin(alpha) * cos(beta) * sin(xi)
c = sin(alpha) * sin(beta) * sin(xi)
d = cos(alpha) * sin(xi)
x, y, z, w = vec
[
a*x - b*y - c*z - d*w,
a*y + b*x + c*w - d*z,
a*z - b*w + c*x + d*y,
a*w + b*z - c*y + d*x
]
end
# stereographic projection
function stereog(v)
Meshes.Point(v[1:3] / (sqrt(2) - v[4]))
end
function duoprism(xi)
# rotated and projected vertices
vs = [stereog(rotate4d(pi/2, 0, xi, duoprismVertices[i, j, :])) for i = 1:A, j = 1:B]
## edges
function cylinder(k)
p1 = vs[edges[1, 1, k], edges[2, 1, k]]
p2 = vs[edges[1, 2, k], edges[2, 2, k]]
s = Meshes.Segment(p1, p2)
Meshes.Cylinder(0.06, s)
end
tubes = [cylinder(k) for k = 1:(2*A*B)]
function sphere(i, j)
p = vs[i, j]
Meshes.Sphere(p, 0.1)
end
mesh = reduce(merge, tubes)
spheres = [Meshes.discretize(sphere(i, j), Meshes.RegularDiscretization(20)) for i in 1:A, j in 1:B]
merge(mesh, reduce(merge, spheres))
end
nplots = 60
meshes = [duoprism(xi) for xi in LinRange(0, 2*pi/4, nplots+1)[1:nplots]]
function draw(i)
MeshViz.viz!(meshes[i]; color = :green)
end
for i in 1:nplots
figg, axx, pltt = MeshViz.viz(Meshes.Box(Meshes.Point(-2.5, -2.5, -0.5), Meshes.Point(2.5, 2.5, 1.5)); alpha = 0)
axx.show_axis = false
draw(i)
scale!(axx.scene, 1.6, 1.6, 1.6)
Makie.rotate!(axx.scene, 1,0,0)
png = @sprintf "duoprism%02d.png" i
Makie.save(png, figg)
end
comm = @cmd "convert -layers OptimizePlus -delay 1x10 'duoprism*.png' duoprism.gif"
# run(comm)