Identify knot intervals or triangles and compute barycentric coordinates
Usage
fm_bary(mesh, loc, ...)
# S3 method for fm_mesh_1d
fm_bary(mesh, loc, method = c("linear", "nearest"), restricted = FALSE, ...)
# S3 method for fm_mesh_2d
fm_bary(mesh, loc, crs = NULL, ...)
# S3 method for inla.mesh
fm_bary(mesh, ...)
# S3 method for inla.mesh.1d
fm_bary(mesh, ...)
Arguments
- mesh
fm_mesh_1d
orfm_mesh_2d
object- loc
Points for which to identify the containing interval/triangle, and corresponding barycentric coordinates. May be a vector (for 1d) or a matrix of raw coordinates,
sf
, orsp
point information (for 2d).- ...
Arguments forwarded to sub-methods.
- method
character; method for defining the barycentric coordinates, "linear" (default) or "nearest"
- restricted
logical, used for
method="linear"
. IfFALSE
(default), points outside the mesh interval will be given barycentric weights less than 0 and greater than 1, according to linear extrapolation. IfTRUE
, the barycentric weights are clamped to the (0, 1) interval.- crs
Optional crs information for
loc
Value
A list with elements t
; either
vector of triangle indices (triangle meshes),
matrix of interval knot indices (1D meshes), or
matrix of lower left box indices (2D lattices),
and bary
, a matrix of barycentric coordinates.
Methods (by class)
fm_bary(fm_mesh_1d)
: Return a list with elementst
(start and endpoint knot indices) andbary
(barycentric coordinates), both 2-column matrices.For
method = "nearest"
,t[,1]
contains the index of the nearest mesh knot, and each row ofbary
containsc(1, 0)
.fm_bary(fm_mesh_2d)
: A list with elementst
(vector of triangle indices) andbary
(3-column matrix of barycentric coordinates). Points that were not found giveNA
entries int
andbary
.
Examples
str(fm_bary(fmexample$mesh, fmexample$loc_sf))
#> List of 2
#> $ t : int [1:10] 331 303 425 342 377 223 365 92 92 359
#> $ bary: num [1:10, 1:3] 0.316 0.137 0.485 0.292 0.625 ...
str(fm_bary(fm_mesh_1d(1:4), seq(0, 5, by = 0.5)))
#> List of 2
#> $ t : num [1:11, 1:2] 1 1 1 1 2 2 3 3 3 3 ...
#> $ bary: num [1:11, 1:2] 2 1.5 1 0.5 1 0.5 1 0.5 0 -0.5 ...