Identify knot intervals or triangles and compute barycentric coordinates
Usage
fm_bary(...)
# S3 method for class 'fm_bary'
fm_bary(bary, ...)
# S3 method for class 'list'
fm_bary(bary, ...)
# S3 method for class 'tbl_df'
fm_bary(bary, ...)
# S3 method for class 'fm_mesh_1d'
fm_bary(mesh, loc, method = c("linear", "nearest"), restricted = FALSE, ...)
# S3 method for class 'fm_mesh_2d'
fm_bary(mesh, loc, crs = NULL, ..., max_batch_size = NULL)
Arguments
- ...
Arguments forwarded to sub-methods.
- bary
An
fm_bary
object, or an object that can be converted tofm_bary
.- 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).- 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
- max_batch_size
integer; maximum number of points to process in a single batch. This speeds up calculations by avoiding repeated large internal memory allocations and data copies. The default,
NULL
, usesmax_batch_size = 2e5L
, chosen based on empirical time measurements to give an approximately optimal runtime.
Value
A fm_bary
object, a tibble
with columns index
; either
vector of triangle indices (triangle meshes),
matrix of interval knot indices (1D meshes), or
matrix of lower left box indices (2D lattices),
and where
, a matrix of barycentric coordinates.
Methods (by class)
fm_bary(fm_bary)
: Returns thebary
input unchangedfm_bary(list)
: Converts alist
bary
tofm_bary
. In the list elements are unnamed, the namesindex
andwhere
are assumed.fm_bary(tbl_df)
: Converts atibble::tibble()
bary
tofm_bary
fm_bary(fm_mesh_1d)
: Return anfm_bary
object with elementsindex
(edge index vector pointing to the first knot of each edge) andwhere
(barycentric coordinates, 2-column matrices). Usefm_bary_simplex()
to obtain the corresponding endpoint knot indices.For
method = "nearest"
,index
contains the index of the nearest mesh knot, andwhere
is a single-column all-ones matrix.fm_bary(fm_mesh_2d)
: Anfm_bary
object with columnsindex
(vector of triangle indices) andwhere
(3-column matrix of barycentric coordinates). Points that were not found giveNA
entries inindex
andwhere
.
Examples
bary <- fm_bary(fm_mesh_1d(1:4), seq(0, 5, by = 0.5))
bary
#> # A tibble: 11 × 2
#> index where[,1] [,2]
#> * <int> <dbl> <dbl>
#> 1 1 2 -1
#> 2 1 1.5 -0.5
#> 3 1 1 0
#> 4 1 0.5 0.5
#> 5 2 1 0
#> 6 2 0.5 0.5
#> 7 3 1 0
#> 8 3 0.5 0.5
#> 9 3 0 1
#> 10 3 -0.5 1.5
#> 11 3 -1 2
str(fm_bary(fmexample$mesh, fmexample$loc_sf))
#> fm_bary [10 × 2] (S3: fm_bary/tbl_df/tbl/data.frame)
#> $ index: int [1:10] 358 301 413 337 369 221 363 329 329 142
#> $ where: num [1:10, 1:3] 0.0699 0.1367 0.4852 0.0831 0.6245 ...