根据delaunay三角形值建立邻接矩阵

时间:2018-05-04 08:19:05

标签: r geometry adjacency-matrix delaunay

我有一个包含点的3D坐标的大矩阵,我希望使用它们的delaunay三角测量结果得到它们的邻接矩阵。为了获得他们使用的delaunay三角测量值,几何'包。为了得到我所拥有的一个例子,我准备了以下代码:

values<-rnorm(12,mean = 10, 5)

mat<-matrix(values,ncol = 3)

dimnames(mat)<-list(c("asd","qwe","rty","poi"),c("x","y","z"))

require("geometry")

delaunaynMat<-delaunayn(mat)

然而,我找不到任何适当的函数来从delaunay结果构建邻接矩阵。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

也许使用DatabionicSwarm

> library(DatabionicSwarm)
> Delaunay4Points(mat, IsToroid=FALSE)
  1 2 3 4
1 0 1 1 1
2 1 0 1 1
3 1 1 0 0
4 1 1 0 0

或wirh deldir(仅适用于2D):

> require(deldir) 
Loading required package: deldir
deldir 0.1-15
> set.seed(42) 
> x <- runif(6) 
> y <- runif(6) 
> dxy <- deldir(x,y) 
> ind <- dxy$dirsgs[,5:6] 
> adj <- matrix(0, length(x), length(y)) 
> for (i in 1:nrow(ind)){ 
+     adj[ind[i,1], ind[i,2]] <- 1 
+     adj[ind[i,2], ind[i,1]] <- 1 
+ } 
> adj 
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    1    0    1    0    0
[2,]    1    0    0    1    1    0
[3,]    0    0    0    0    1    1
[4,]    1    1    0    0    1    1
[5,]    0    1    1    1    0    1
[6,]    0    0    1    1    1    0

修改

有些奇怪的东西。我需要翻转Delaauny4Points矩阵以获得与deldir一致的结果:

set.seed(42) 
x <- runif(6) 
y <- runif(6) 
dxy <- deldir(x,y) 
ind <- dxy$delsgs[,5:6] 
adj <- matrix(0, length(x), length(y)) 
for (i in 1:nrow(ind)){ 
    adj[ind[i,1], ind[i,2]] <- 1 
    adj[ind[i,2], ind[i,1]] <- 1 
} 
adj
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    1    0    1    0    1
[2,]    1    0    1    1    1    0
[3,]    0    1    0    0    1    1
[4,]    1    1    0    0    1    1
[5,]    0    1    1    1    0    1
[6,]    1    0    1    1    1    0

> Delaunay4Points(cbind(x,y), IsToroid=FALSE)[6:1,6:1] # <- look
  6 5 4 3 2 1
6 0 1 0 1 0 1
5 1 0 1 1 1 0
4 0 1 0 0 1 1
3 1 1 0 0 1 1
2 0 1 1 1 0 1
1 1 0 1 1 1 0