from
0.3.0.9001
.
Create hexagon lattice
points within a boundary. The hexagonal lattice is anchored at the
coordinate system origin, so that grids with different but overlapping
boundaries will have matching points.
Arguments
- bnd
Boundary object (currently must be an
sf
polygon)- edge_len
Triangle edge length
- buffer_n
Number of triangle height multiples for buffer inside the boundary object to the start of the lattice. Default 0.49.
- align
Alignment of the hexagon lattice, either a length-2 numeric, or character, a sf/sfc/sfg object containing a single point), or
character
, default"origin"
:- "origin"
align the lattice with the coordinate system origin
- "bbox"
align the lattice with the midpoint of the bounding box of
bnd
- "centroid"
align the lattice with the centroid of the boundary,
sf::st_centroid(bnd)
- meta
logical; if
TRUE
, return a list with diagnostic information from the lattice construction (including the points themselves inlattice
)
Value
An sfc
object with points, if meta
is FALSE
(default), or if
meta=TRUE
, a list:
- lattice
sfc
with lattice points- edge_len
numeric
with edge length- bnd_inner
sf
object with the inner boundary used to filter points outside of aedge_len * buffer_n
distance from the boundary- grid_n
integer
with the number of points in each direction prior to filtering- align
numeric
with the alignment coordinates of the hexagon lattice
Author
Man Ho Suen M.H.Suen@sms.ed.ac.uk, Finn Lindgren Finn.Lindgren@gmail.com
Examples
(m <- fm_mesh_2d(
fm_hexagon_lattice(
fmexample$boundary_sf[[1]],
edge_len = 0.1 * 5
),
max.edge = c(0.2, 1) * 5,
boundary = fmexample$boundary_sf
))
#> fm_mesh_2d object:
#> Manifold: R2
#> V / E / T: 189 / 537 / 349
#> Euler char.: 1
#> Constraints: Boundary: 27 boundary edges (1 group: 1), Interior: 49 interior edges (1 group: 1)
#> Bounding box: (-5.331027, 4.061656) x (-3.998161, 5.415609)
#> Basis d.o.f.: 189
(m2 <- fm_mesh_2d(
fm_hexagon_lattice(
fmexample$boundary_sf[[1]],
edge_len = 0.1 * 5,
align = "centroid"
),
max.edge = c(0.2, 1) * 5,
boundary = fmexample$boundary_sf
))
#> fm_mesh_2d object:
#> Manifold: R2
#> V / E / T: 195 / 554 / 360
#> Euler char.: 1
#> Constraints: Boundary: 28 boundary edges (1 group: 1), Interior: 50 interior edges (1 group: 1)
#> Bounding box: (-5.331027, 4.061656) x (-3.998161, 5.415609)
#> Basis d.o.f.: 195
if (require("ggplot2", quietly = TRUE) &&
require("patchwork", quietly = TRUE)) {
((ggplot() +
geom_fm(data = m) +
geom_point(aes(0, 0), col = "red")) |
(ggplot() +
geom_fm(data = m2) +
geom_point(aes(0, 0), col = "red") +
geom_sf(data = sf::st_centroid(fmexample$boundary_sf[[1]]))
)
)
}