# Meshes.Vec is ambiguous

**URL:** <https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836>\
**Category:** General Usage\
**Tags:** package\
**Created:** [October 11, 2023, 9:13am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836 "2023-10-11T09:13:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 9:13am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/1 "2023-10-11T09:13:21Z")

</div>

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?

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 10:36am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/2 "2023-10-11T10:36:33Z")

</div>

@juliohm I fixed that. But now, when I run `duoprism(1)`, I get a StackOverflow.

```julia
using Printf
import Makie
import Meshes 
import MeshViz

A = 4
B = 4

# 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)
  v[1:3]/ (sqrt(2) - v[4])
end

# rotated vertices
function rvs(xi)
  [stereog(rotate4d(pi/2, 0, xi, duoprismVertices[i, j, :])) for i = 1:A, j = 1:B]
end

function cylinder(xi, k)
  vs = rvs(xi)
  p1 = vs[edges[1, 1, k], edges[2, 1, k]]
  p2 = vs[edges[1, 2, k], edges[2, 2, k]]
# s = Meshes.Segment(Meshes.Point(tuple(p1)), Meshes.Point(tuple(p2)))
  Meshes.Cylinder(tuple(p1...), tuple(p2...), 0.06)
end

function tubes(xi)
  [cylinder(xi, k) for k = 1:(2*A*B)]
end

function duoprism(xi)
  # rotated and projected vertices
  vs = rvs(xi)
  ## edges
  duoedges = tubes(xi)
  function sphere(i, j)
    p = vs[i, j]
    Meshes.Sphere(tuple(p...), 0.1)
  end
  mesh = reduce(Meshes.merge, duoedges)
  spheres = [Meshes.discretize(sphere(i, j), Meshes.RegularDiscretization(20)) for i in 1:A, j in 1:B]
  Meshes.merge(mesh, reduce(Meshes.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)
  Makie.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)

```

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [October 11, 2023, 10:48am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/3 "2023-10-11T10:48:55Z")

</div>

Vec is constructed with static vector or tuple. We should probably add a method to catch this error and alert users who try to use dynamic vectors.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 10:55am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/4 "2023-10-11T10:55:26Z")

</div>

It works now, but there’s the Stackoverflow.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 11:00am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/5 "2023-10-11T11:00:37Z")

</div>

By the way, the doc of `Cylinder` is wrong, it doesn’t work with a `Segment`.

![cylinder](https://global.discourse-cdn.com/julialang/original/3X/9/f/9f232edc379a486a1c7a7a48843fc75bff7fa7f5.png)

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [October 11, 2023, 11:05am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/6 "2023-10-11T11:05:39Z")

</div>

Please create a MWE

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [October 11, 2023, 11:06am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/7 "2023-10-11T11:06:23Z")

</div>

Please open an issue on github. That is the place for issues.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 11:07am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/8 "2023-10-11T11:07:25Z")

</div>

For the StackOverflow ? Hard to minimize my code.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [October 11, 2023, 11:24am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/9 "2023-10-11T11:24:26Z")

</div>

StackOverflow can come from anywhere. If you are suspecting that it comes from Meshes.jl then please reduce the example to the specific lines that you have suspicion. I don’t have the time to create the MWE for you.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 11:28am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/10 "2023-10-11T11:28:25Z")

</div>

I have no idea whether it comes from Meshes.jl or from a bad practice. I will try to minimize.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [October 11, 2023, 11:29am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/11 "2023-10-11T11:29:13Z")

</div>

You can start by loading a single package instead of 3.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 11:29am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/12 "2023-10-11T11:29:17Z")

</div>

But I’m sure this code worked previously. I posted the animation on Zulip, I remember.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [October 11, 2023, 11:29am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/13 "2023-10-11T11:29:59Z")

</div>

If you update software versions you should expect breaking changes sometimes. There is no guarantee that a code working in previous versions will keep working in the future.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 11:51am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/14 "2023-10-11T11:51:01Z")

</div>

I found the problem but not its solution. If I separate the merges edges (`mesh` below) and the spheres, this works. The problem is this line:

```julia
Meshes.merge(mesh, reduce(Meshes.merge, spheres))

```

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [October 11, 2023, 11:59am UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/15 "2023-10-11T11:59:09Z")

</div>

Nice. Now you need to create the MWE showing this stackoverflow with a specific small `mesh` and `spheres`.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 12:07pm UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/16 "2023-10-11T12:07:49Z")

</div>

I think I have the solution now: `cat(1, theSpheres(xi), theEdges(xi))`.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 12:40pm UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/17 "2023-10-11T12:40:13Z")

</div>

Forget that, bullshit, I did a mistake.

I definitely have to separate the spheres and the cylinders, otherwise the merging generates the stackoverflow. Looks like a bug. I will prepare a minimal code.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 12:53pm UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/18 "2023-10-11T12:53:23Z")

</div>

![Duoprism](https://global.discourse-cdn.com/julialang/original/3X/b/1/b1de758baa3b853fa0aa19c8acc2f392b1a89ab1.gif)

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 1:47pm UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/19 "2023-10-11T13:47:14Z")

</div>

![Duoprism](https://global.discourse-cdn.com/julialang/original/3X/9/d/9dde7de832362aab1581119b5bd2a987c943e302.gif)

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [October 11, 2023, 1:48pm UTC](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836/20 "2023-10-11T13:48:50Z")

</div>

@juliohm What about a gallery of pictures/animations for Meshes.jl? Could be nice.

[Next page](https://discourse.julialang.org/t/meshes-vec-is-ambiguous/104836.md?page=2)
