我想在rgl繪圖中識別 3d 圓柱體以獲得最近/選定圓柱體的一個屬性。我嘗試使用標簽來簡單地拼出屬性,但我處理的資料超過 10.000 個圓柱體。因此,它變得如此擁擠以至于標簽不可讀并且需要很長時間才能呈現。
我試圖了解檔案,rgl我想我的問題的解決方案是手動選擇圖中的圓柱體。我相信這個功能selectpoints3d()可能是要走的路。我相信它會回傳繪制矩形內的所有頂點,但我不知道如何回傳圓柱資料?我可以計算出哪個圓柱最接近所選頂點的平均值,但這似乎是一種“快速而骯臟”的作業方式。
有更好的方法嗎?我注意到value=FALSE僅獲取索引的論點,但我不知道如何回傳氣缸。
這是一些虛擬資料和我的代碼:
# dummy data
cylinder <- data.frame(
start_X = rep(1:3, 2)*2,
start_Y = rep(1:2, each = 3)*2,
start_Z = 0,
end_X = rep(1:3, 2)*2 round(runif(6, -1, 1), 2),
end_Y = rep(1:2, each = 3)*2 round(runif(6, -1, 1), 2),
end_Z = 0.5,
radius = 0.25,
attribute = sample(letters[1:6], 6)
)
# calculate centers
cylinder$center_X <- rowMeans(cylinder[,c("start_X", "end_X")])
cylinder$center_Y <- rowMeans(cylinder[,c("start_Y", "end_Y")])
cylinder$center_Z <- rowMeans(cylinder[,c("start_Z", "end_Z")])
# create cylinders
cylinder_list <- list()
for (i in 1:nrow(cylinder)) {
cylinder_list[[i]] <- cylinder3d(
center = cbind(
c(cylinder$start_X[i], cylinder$end_X[i]),
c(cylinder$start_Y[i], cylinder$end_Y[i]),
c(cylinder$start_Z[i], cylinder$end_Z[i])),
radius = cylinder$radius[i],
closed = -2)
}
# plot cylinders
open3d()
par3d()
shade3d(shapelist3d(cylinder_list, plot = FALSE), col = "blue")
text3d(cylinder$center_X 0.5, cylinder$center_Y 0.5, cylinder$center_Z 0.5, cylinder$attribute, color="red")
# get attribute
nearby <- selectpoints3d(value=TRUE, button = "right")
nearby <- colMeans(nearby)
cylinder$dist <- sqrt(
(nearby["x"]-cylinder$center_X)**2
(nearby["y"]-cylinder$center_Y)**2
(nearby["z"]-cylinder$center_Z)**2)
cylinder$attribute[which.min(cylinder$dist)]
uj5u.com熱心網友回復:
如果你打電話selectpoints3d(value = FALSE),你會得到兩列。第一列是找到的物件的 ID。您的氣缸每個都有兩個 id。標記圓柱體的一種方法是使用“標簽”。例如,您的代碼的這種修改:
# dummy data
cylinder <- data.frame(
start_X = rep(1:3, 2)*2,
start_Y = rep(1:2, each = 3)*2,
start_Z = 0,
end_X = rep(1:3, 2)*2 round(runif(6, -1, 1), 2),
end_Y = rep(1:2, each = 3)*2 round(runif(6, -1, 1), 2),
end_Z = 0.5,
radius = 0.25,
attribute = sample(letters[1:6], 6)
)
# calculate centers
cylinder$center_X <- rowMeans(cylinder[,c("start_X", "end_X")])
cylinder$center_Y <- rowMeans(cylinder[,c("start_Y", "end_Y")])
cylinder$center_Z <- rowMeans(cylinder[,c("start_Z", "end_Z")])
# create cylinders
cylinder_list <- list()
for (i in 1:nrow(cylinder)) {
cylinder_list[[i]] <- cylinder3d(
center = cbind(
c(cylinder$start_X[i], cylinder$end_X[i]),
c(cylinder$start_Y[i], cylinder$end_Y[i]),
c(cylinder$start_Z[i], cylinder$end_Z[i])),
radius = cylinder$radius[i],
closed = -2)
# Add tag here:
cylinder_list[[i]]$material$tag <- cylinder$attribute[i]
}
# plot cylinders
open3d()
par3d()
shade3d(shapelist3d(cylinder_list, plot = FALSE), col = "blue")
text3d(cylinder$center_X 0.5, cylinder$center_Y 0.5, cylinder$center_Z 0.5, cylinder$attribute, color="red")
# Don't get values, get the ids
nearby <- selectpoints3d(value=FALSE, button = "right", closest = FALSE)
ids <- nearby[, "id"]
# Convert them to tags. If you select one of the labels, you'll get
# a blank in the list of tags, because we didn't tag the text.
unique(tagged3d(id = ids))
當我嘗試這個時,我發現使用closest = TRUEinselectpoints3d似乎得到了太多的 id;那里可能有一個錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/430481.html
上一篇:每組做分位數
