# ---------- 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