如何找到多个点之间所有点的坐标?

how to find coordinates of all points between multiple points?

在问题中我有几个点,我们称它们为 A、B 和 C(但它们可以更多),我知道它们在 (x, y) 中的位置。我还有一个定义的区域,范围在两个轴上的 [1-n] 之间。我需要找到落在由 A、B 和 C 生成的多边形中的所有点。

因为我没有点集,所以我想使用 x 轴和 y 轴的整个范围,即 [1-n],作为落在由 A 生成的多边形中的可能点集、B 和 C,但我不确定这是否是该功能的设计目的。

在这个阶段,我尝试了一些涉及以下功能的东西(其中我在 SO 中发现了其他问题)。

#define the range as the possible points falling in the polygon
allPointsX <- allPointsY <- c(1:2048)
#get some coordinates for three points generating the actual polygon (which in this case is a simple triangle)
xCoord <- c(127, 120, 152)
yCoord <- c(77, 96, 107)
#look for points into the polygon
points <- point.in.polygon(allPointsX, allPointsY, xCoord, yCoord)

但要么我没有得到输出(全为零:all(points==0)),要么这不是我要找的。

有什么建议吗?我错过了什么?

您的代码是正确的。只是你所有的点都在三角形之外。

library(tidyverse)

ggplot(mapping = aes(x, y)) +
  geom_point(data = tibble(x = allPointsX, y = allPointsY)) +
  geom_polygon(data = tibble(x = xCoord, y = yCoord)) +
  xlim(75, 160) +
  ylim(75, 160)

这是一个位于三角形内部的点。

sp::point.in.polygon(127, 78, xCoord, yCoord)
#> [1] 1