find_xy | R Documentation |
This function finds the coordinates of specified mesh cells. For nodes, these can be extracted from the nodexy
dataframe or from the mesh. The latter method is not quite as accurate and is slower; this difference may become noticeable for large meshes. However, for elements, the extraction of coordinates from the mesh is the only implemented method.
find_xy(mesh_ID, mesh, nodexy = NULL)
mesh_ID |
A vector of integers which define the mesh IDs for which coordinates are desired. |
mesh |
A mesh, created by |
nodexy |
(optional) A dataframe with columns which specify the coordinates and IDs of each cell in the mesh around nodes in columns named 'node_id', 'x' and 'y' (see |
The function returns a dataframe with mesh IDs ('mesh_ID') and corresponding coordinates ('x' and 'y').
Edward Lavender
#### Define mesh cells for which we want to extract coordinates # In this hypothetical situation, we'll use mesh IDs for which we know their coordinates # ... so that we can compare the two approaches: set.seed(1) select <- sample(1:nrow(dat_nodexy), 10) dat <- dat_nodexy[select, ] #### Examples: find_xy using nodexy and mesh options respectively dat_xy1 <- find_xy(dat$node_id, nodexy = dat_nodexy) dat_xy2 <- find_xy(dat$node_id, mesh = dat_mesh_around_nodes) #### Coordinates from the nodexy method are exactly correct but coordinates from the mesh # ... are not as accurate: identical(dat, dat_xy1) identical(dat, dat_xy2) cbind(dat, dat_xy1, dat_xy2) #### The nodexy approach is also considerably faster. For these reasons, the nodexy # ... approach is recommended for node cells where possible. microbenchmark::microbenchmark(find_xy(dat$node_id, nodexy = dat_nodexy), find_xy(dat$node_id, mesh = dat_mesh_around_nodes) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.