JuliaGeometry/Meshes.jl

Function to remove internal edges of 2D mesh

Open

#1,195 opened on May 16, 2025

View on GitHub
 (11 comments) (0 reactions) (0 assignees)Julia (98 forks)auto 404
featurehelp wanted

Repository metrics

Stars
 (460 stars)
PR merge metrics
 (PR metrics pending)

Description

is there a function to remove internal edges in a 2D mesh? say for example i have a mesh with two quadrangles which touch like this:

julia> using Meshes, GLMakie

julia> points1 = [(0,0), (1,0), (0,1), (1,1), (1,0), (2,0), (1,1), (2,1)];

julia> quads1 = connect.([(1,2,4,3), (5,6,8,7)], Quadrangle);

julia> mesh1 = SimpleMesh(points1, quads1)
2 SimpleMesh
  8 vertices
  ├─ Point(x: 0.0 m, y: 0.0 m)
  ├─ Point(x: 1.0 m, y: 0.0 m)
  ├─ Point(x: 0.0 m, y: 1.0 m)
  ├─ Point(x: 1.0 m, y: 1.0 m)
  ├─ Point(x: 1.0 m, y: 0.0 m)
  ├─ Point(x: 2.0 m, y: 0.0 m)
  ├─ Point(x: 1.0 m, y: 1.0 m)
  └─ Point(x: 2.0 m, y: 1.0 m)
  2 elements
  ├─ Quadrangle(1, 2, 4, 3)
  └─ Quadrangle(5, 6, 8, 7)

julia> viz(mesh1, showsegments=true)

i'd like to programmatically simplify this to a single quadrangle like this:

julia> points2 = [(0,0), (2,0), (0,1), (2,1)];

julia> quads2 = connect.([(1,2,4,3)], Quadrangle);

julia> mesh2 = SimpleMesh(points2, quads2)
1 SimpleMesh
  4 vertices
  ├─ Point(x: 0.0 m, y: 0.0 m)
  ├─ Point(x: 2.0 m, y: 0.0 m)
  ├─ Point(x: 0.0 m, y: 1.0 m)
  └─ Point(x: 2.0 m, y: 1.0 m)
  1 elements
  └─ Quadrangle(1, 2, 4, 3)

julia> viz(mesh2, showsegments=true)

Contributor guide