有效计算网格上的点的方法
假设我有一个均匀分布的 6 x 6 点网格:
width <- 6
N <- width^2
x_cent <- rep(seq(from = 0, to = 1, length.out = width), times = width)
y_cent <- rep(seq(from = 0, to = 1, length.out = width), each = width)
dat <- tibble::as_tibble(cbind(x_cent, y_cent)) %>%
dplyr::mutate(unit_id = rep(1:nrow(.)))
我想计算/知道排列 2 x 4(例如 2 和 4 的长度/宽度)点组的所有可能方法(占“剩余”组)不需要空间分组的4个点)。 R 中是否有有效的方法来计算或迭代这些组?请注意,这些组不应相互重叠;它们在空间上应该是不同的。
我尝试编写一种算法,在 (0, 0) 处创建 2x4 或 4x2(例如水平或垂直放置)组,然后尝试将其余点适合组,但我无法编写足够的规则指导算法将点正确分组在一起。
Say I have an evenly spaced 6 x 6 grid of points:
width <- 6
N <- width^2
x_cent <- rep(seq(from = 0, to = 1, length.out = width), times = width)
y_cent <- rep(seq(from = 0, to = 1, length.out = width), each = width)
dat <- tibble::as_tibble(cbind(x_cent, y_cent)) %>%
dplyr::mutate(unit_id = rep(1:nrow(.)))
I want to calculate/ know all the possible ways to arrange 2 x 4 (e.g. length/width of 2 and 4) groups of points (accounting for a "residual" group of 4 points which does not need to be spatially grouped). Is there an efficient way to calculate or iterate over these groups in R? Note that these groups should not overlap with one another; they should all be spatially distinct.
I have tried to write an algorithm that creates a 2x4 or 4x2 (e.g. either horizontally or vertically placed) group at (0, 0) that then tries to fit the remaining points to groups, but I haven't been able to write enough rules to guide the algorithm to correctly group points together.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论