簡體   English   中英

如何找到多個點之間所有點的坐標?

[英]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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM