Learn R Programming

SpatialfdaR (version 1.0.0)

insideIndex: Index of the triangle containing a point.

Description

Evaluate the index of the triangle containing the point (X,Y) if such a triangle exists, and NaN otherwise.

Usage

insideIndex(obspts, pts, tri, tricoef)

Value

A vector of integers indicating which triangle in tri contains a point.

Arguments

obspts

A two-column matrix of observation location points.

pts

A two-column matrix of the locations of the vertices of the mesh.

tri

A three-column matrix of the indices in pts of the triangle vertices.

tricoef

Four-column matrix of coefficients for computing barycentric coordinates.

Details

Each triangle is checked to see if the point is contained within it or on its boundary. This is verified if all three of the barycentric coordinates are non-negative.

See Also

FEMdensity, eval.FEM.basis

Examples

Run this code
#  ---------- density on a unit square,  4 triangles, 5 vertices  ----------
#  Generate a unit square with a node in its center defining four
#  triangles and five nodes.
result <- squareMesh(1)
pts  <- result$p
edg  <- result$e
tri  <- result$t
npts <- dim(pts)[1]
ntri <- dim(tri)[1]
#  define function for sine*cosine function
SinCosIntensFn <- function(x,y) {
  return(sin(2*pi*x)*cos(2*pi*y))
}
#  Compute a sine*cosine intensity surface.
intDensityVec <- triDensity(pts, tri, SinCosIntensFn)
#  Set up and plot an FEM basis object
SquareBasis1 <- create.FEM.basis(pts, edg, tri)
oldpar <- par(cex.lab=2)
plotFEM.mesh(pts, tri)
#  generate random points
N = 1000
obspts <- randomFEMpts(N, pts, tri, intDensityVec)
#  plot the random points
points(obspts[,1],obspts[,2])
#  find the triangle number containing each point
triIndex <- insideIndex(obspts, pts, tri)
par(oldpar)

Run the code above in your browser using DataLab