How do I access the faces of a 3D element in Meshes.jl?

Hello!

I am very new to Meshes.jl and getting a bit perplexed by all of it, since I cannot really find any good examples other than the quick examples, and I atleast cannot find what I want to do.

I have one single box element and I want to plot the normals on all the outer surfaces. Currently the code produces:

As you see I am missing 7 of them :slight_smile: How do I loop over faces, and preferably in such a way the code would also work for 2D?

The code is here:

using Meshes
using MeshViz
using GLMakie
using LinearAlgebra
using Statistics

grid = CartesianGrid(1,1,1)
display(viz(grid , showfacets = true, alpha=0.25))

function ExtractMidpoints(p)
    o  = p.vertices

    mp = mean(map(x->x.coords,o))

    return mp
end

function GenerateGridNormal(p)
    o = p.vertices
    
    p1 = o[1]
    p2 = o[2]
    p3 = o[3]

    v1 = p2 - p1
    v2 = p3 - p1

    n  = cross(v1,v2)

    n /= norm(n)

    return n
end



mps = Tuple.(ExtractMidpoints.(grid))
nms = Tuple.(GenerateGridNormal.(grid))

scatter!(Tuple.(ExtractMidpoints.(grid)))
arrows!(first.(mps),getindex.(mps,2),last.(mps),first.(nms),getindex.(nms,2),last.(nms))

Kind regards

Just bumping my thread, since I have still not figured out to do so. It should be really simple, I just cannot find the right syntax :slight_smile:

Maybe faces(mesh, 2) is what you’re lookimg for? (Sorry, I’m from phone nor can I test it or check my code that did something similae.)

This returns:

faces(grid,2)
Base.Generator{Base.Generator{UnitRange{Int64}, Meshes.var"#94#95"{GridTopology{3}}}, Meshes.var"#131#132"{CartesianGrid{3, Float64}}}(Meshes.var"#131#132"{CartesianGrid{3, Float64}}(1Ă—1Ă—1 CartesianGrid{3,Float64}), Base.Generator{UnitRange{Int64}, Meshes.var"#94#95"{GridTopology{3}}}(Meshes.var"#94#95"{GridTopology{3}}(1Ă—1Ă—1 GridTopology(aperiodic, aperiodic, aperiodic)), 1:6))

Which I am not familiar at all with, i.e. how to use. When I then try:

for f in faces(grid,2)
       print(f)
       end
┌ Error: not implemented

And then I try:

 collect(faces(grid,2))
┌ Error: not implemented

Which just seems weird to me, it seems to me atleast, that it is a basic need being able to loop over faces, edges, vertices etc.

Kind regards

@juliohm kindly showed me how to do it.

grid = CartesianGrid(1,1,1)

boundary(grid[1])
6 SimpleMesh{3,Float64}
  8 vertices
    └─Point(0.0, 0.0, 0.0)
    └─Point(1.0, 0.0, 0.0)
    └─Point(1.0, 1.0, 0.0)
    └─Point(0.0, 1.0, 0.0)
    └─Point(0.0, 0.0, 1.0)
    └─Point(1.0, 0.0, 1.0)
    └─Point(1.0, 1.0, 1.0)
    └─Point(0.0, 1.0, 1.0)
  6 elements
    └─Quadrangle(4, 3, 2, 1)
    └─Quadrangle(6, 5, 1, 2)
    └─Quadrangle(3, 7, 6, 2)
    └─Quadrangle(4, 8, 7, 3)
    └─Quadrangle(1, 5, 8, 4)
    └─Quadrangle(6, 7, 8, 5)

I knew it was there, I just couldn’t find it! :sweat_smile:

Kind regards