How can I generate a 3D annulus surface and mesh it using Meshes.jl?

I have tried using PolyArea. Here is MME:

ring1=Meshes.Ring([(cos(t),sin(t),0) for t in 0.1:0.1:2pi])
ring2=Meshes.Ring([(2cos(t),2sin(t),0) for t in 0.1:0.1:2pi])
annulus = PolyArea([ring2, ring1])
discretize(annulus, FanTriangulation())

with error:

ERROR: DimensionMismatch: Sizes (Size(3,), Size(2,)) of input arrays do not match 
Stacktrace:
  [1] _throw_size_mismatch(::Meshes.Vec3, ::Vararg{Any})
    @ StaticArrays C:\Users\Administrator\.julia\packages\StaticArrays\Uc4hE\src\traits.jl:113
  [2] same_size
    @ C:\Users\Administrator\.julia\packages\StaticArrays\Uc4hE\src\traits.jl:107 
[inlined]
  [3] macro expansion
    @ C:\Users\Administrator\.julia\packages\StaticArrays\Uc4hE\src\mapreduce.jl:74 [inlined]
  [4] _map
    @ C:\Users\Administrator\.julia\packages\StaticArrays\Uc4hE\src\mapreduce.jl:40 [inlined]
  [5] map
    @ C:\Users\Administrator\.julia\packages\StaticArrays\Uc4hE\src\mapreduce.jl:37 [inlined]
  [6] +
    @ C:\Users\Administrator\.julia\packages\StaticArrays\Uc4hE\src\linalg.jl:12 [inlined]
  [7] +(A::Meshes.Point3, v::Meshes.Vec2)    @ Meshes C:\Users\Administrator\.julia\packages\Meshes\1sXKx\src\primitives\point.jl:95
  [8] bridge(rings::Vector{Meshes.Ring{…}}, rinds::Vector{Vector{…}}, δ::Float64) 
    @ Meshes C:\Users\Administrator\.julia\packages\Meshes\1sXKx\src\transforms\bridge.jl:81
  [9] apply
    @ C:\Users\Administrator\.julia\packages\Meshes\1sXKx\src\transforms\bridge.jl:30 [inlined]
 [10] discretize(polygon::Meshes.PolyArea{3, Float64, Meshes.Ring{…}}, method::Meshes.FanTriangulation)
    @ Meshes C:\Users\Administrator\.julia\packages\Meshes\1sXKx\src\discretization.jl:52
 [11] top-level scope
    @ e:\Mesh the manifolds\MeshRing.jl:16

You can discretize PolyArea embedded in 2D space. Your 3rd coordinates are all zero, just drop them:

using Meshes

import GLMakie as Mke

ring1 = Ring([(cos(t),sin(t)) for t in 0.1:0.1:2pi])
ring2 = Ring([(2cos(t),2sin(t)) for t in 0.1:0.1:2pi])
annulus = PolyArea([ring2, ring1])

viz(annulus)

image

Given that this polygonal area is not convex, you cannot use FanTriangulation. Simply omit the method, and the package will pick the most appropriate one:

mesh = discretize(annulus)
124 SimpleMesh{2,Float64}
  124 vertices
  ├─ Point(1.9900083305560516, 0.1996668332936563)
  ├─ Point(0.9800665778412416, 0.19866933079506122)
  ├─ Point(0.9950041652780258, 0.09983341664682815)
  ├─ Point(0.9965420970232175, -0.0830894028174964)
  ├─ Point(0.9832684384425845, -0.18216250427209588)
  ⋮
  ├─ Point(1.7710390338826378, -0.9292043588275147)
  ├─ Point(1.8549568614880718, -0.747753329660472)
  ├─ Point(1.920340573300732, -0.5588309963978517)
  ├─ Point(1.966536876885169, -0.36432500854419175)
  └─ Point(1.993084194046435, -0.1661788056349928)
  124 elements
  ├─ Triangle(92, 93, 94)
  ├─ Triangle(92, 94, 95)
  ├─ Triangle(91, 92, 95)
  ├─ Triangle(91, 95, 96)
  ├─ Triangle(90, 91, 96)
  ⋮
  ├─ Triangle(68, 69, 1)
  ├─ Triangle(67, 68, 1)
  ├─ Triangle(66, 67, 1)
  ├─ Triangle(65, 66, 1)
  └─ Triangle(1, 64, 65)
1 Like

Hello, Thank you for correcting my misuse of FanTriangulation. This concrete example does not need a 3-dimensional mesh. However, I have to implement what I have described in the title. Can you give me another suggestion?

I have an idea. Maybe I can create an annulus and mesh it in the plane. Map the vertices of the mashed annulus to 3d space by some linear or nonlinear mapping, and reuse the mesh structures of the origin mash.

Do you mean a Torus?

using Meshes

t = Torus((0,0,0), (1,0,0), (0,1,0), 0.1)

viz(torus)

You can discretize it similarly.

No. I just mean a surface annulus in 3d space. I have implemented this idea:

The codes:

using Meshes, GLMakie, Rotations

ring1 = Meshes.Ring([(cos(t), sin(t)) for t in 0.1:0.1:2pi])
ring2 = Meshes.Ring([(2cos(t), 2sin(t)) for t in 0.1:0.1:2pi])
annulus = PolyArea([ring2, ring1])

mymesh = discretize(annulus)

function rotate_annulus(x)
    rmatrix = RotZXZ(1, 1, 1)
    p = [x.coords[1], x.coords[2], 0]
    rp = rmatrix * p
    Meshes.Point3(rp[1], rp[2], rp[3])
end

function to3d(annulus, map)
    vertices = annulus.vertices
    topology = annulus.topology
    newvertices = map.(vertices)
    SimpleMesh(newvertices, topology)
end

viz(to3d(mymesh, rotate_annulus), showfacets=true)

gives


I am new to Meshes.jl. Probably there are better ways.

1 Like