# Construct two simple meshes:
loc <- matrix(c(0, 1, 0, 1), 2, 2)
mesh1 <- fm_mesh_2d(loc = loc, max.edge = 0.1)
bnd <- fm_nonconvex_hull(loc, 0.3)
mesh2 <- fm_mesh_2d(boundary = bnd, max.edge = 0.1)
# Compute connectivity information:
conn1 <- fm_mesh_components(mesh1)
conn2 <- fm_mesh_components(mesh2)
# One component, simply connected mesh
conn1$info
# Two disconnected components
conn2$info
# Extract the subset mesh for each component:
# (Note: some information is lost, such as fixed segments,
# and boundary edge labels.)
mesh3_1 <- fm_rcdt_2d_inla(
loc = mesh2$loc,
tv = mesh2$graph$tv[conn2$triangle == 1, , drop = FALSE],
delaunay = FALSE
)
mesh3_2 <- fm_rcdt_2d_inla(
loc = mesh2$loc,
tv = mesh2$graph$tv[conn2$triangle == 2, , drop = FALSE],
delaunay = FALSE
)
if (require("ggplot2")) {
ggplot() +
geom_fm(data = mesh3_1, fill = "red", alpha = 0.5) +
geom_fm(data = mesh3_2, fill = "blue", alpha = 0.5)
}
(m <- fm_mesh_3d(
matrix(c(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0), 4, 3, byrow = TRUE),
matrix(c(1, 2, 3, 4), 1, 4, byrow = TRUE)
))
# Compute connectivity information:
(conn <- fm_mesh_components(m))
Run the code above in your browser using DataLab