有效计算网格上的点的方法

发布于 2025-01-20 17:29:25 字数 565 浏览 0 评论 0原文

假设我有一个均匀分布的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文