TriMesh: Mesh generator and Delaunay triangulator for 2D/3D Domains

View source: R/TriMesh.R

TriMeshR Documentation

Mesh generator and Delaunay triangulator for 2D/3D Domains

Description

This function triangulates the polygonal domain by using Delaunay Triangulation.

Usage

TriMesh(bdy, n, pt = NULL, holes = NULL)

Arguments

bdy

A two by N matrix which indicates the outer boundry points of a 2D region.

n

An integer parameter controlling the fineness of the triangulation and subsequent triangulation. As n increases the fineness increases. Usually, n = 8 seems to be a good choice.

holes

A list of vertices that are the inner boundary points, default set to 'NULL' if there is no holes.

Details

In the function, we firstly get grid points inside and on the boundary of the polygon with extreme points bdy and interior holes defined by holes. Then delaunay triangulation is used to generate triangulations by using the grid points. And lastly we delete triangles within the holes or outside the boundary of the region.

Value

V

an N by two matrix that lists vertices with the ith row storing in Cartesian coordinates for the ith vertex. N is the number of vertices.

Tr

a K by three matrix that each row represents one triangle. All the elements are the integers that stand for the indices of vertices in V.

Examples

# rectangular domain
bb = rbind(c(0, 0), c(1, 0), c(1, 1), c(0, 1))
VT = TriMesh(bb, 3)
typeof(VT$V)
typeof(VT$Tr)

# irregular domain
data("horseshoe")
TriMesh(hs, n = 9)

pt = rbind(c(-0.475, -0.5), c(0.020, -0.5), c(0.435, -0.5), c(0.890, -0.5),
c(1.345, -0.5), c(1.800, -0.5), c(2.255, -0.5), c(2.710, -0.5), c(3.165, -0.5),
c(-0.475, 0.5), c(0.020, 0.5), c(0.435, 0.5), c(0.890, 0.5), c(1.345, 0.5),
c(1.800, 0.5), c(2.255, 0.5), c(2.710, 0.5), c(3.165, 0.5))
VT = TriMesh(hs, n = 4, pt = pt)
lines(hs, lwd = 1)
points(pt, pch = 20, col = 4)

data("shape")
TriMesh(shape, 15)

data("weird")
TriMesh(weird, 30)

# region with holes
data("BMP")
TriMesh(BMP$bound, 25, holes = list(as.matrix(BMP$H1), as.matrix(BMP$H2)))

data("mymontreal")
TriMesh(mymontreal$bound, 25, holes = list(mymontreal$H1, mymontreal$H2))

funstatpackages/Triangulation documentation built on July 3, 2024, 5:52 p.m.