I have tried out one code to make geometric graphs in 3D. Below is my R script.
###
get.dist = function(x)
{
sqrt(x[1]^2 + x[2]^2)
}
get.pairs = function(N)
{
M = matrix(0, nrow = N * (N - 1)/2, ncol = 2)
x = 1:N
k = 1
for (i in head(x, -1))
{
for (j in (i + 1):(length(x)))
{
M[k, ] = c(i, j)
k = k +1
}
}
M
}
create.graph = function(N = 100, d = 0.3)
{
rnd.points = matrix(runif(3 * N), ncol = 3)
perms = get.pairs(N)
Edges = apply(perms, 1, FUN = function(x){
vec.diff = rnd.points[x[1], ] - rnd.points[x[2], ]
get.dist(vec.diff)
})
res = cbind(Edges, perms)
colnames(res) = c('E', 'V1', 'V2')
list(M = res, N = N, d = d, pts = rnd.points)
}
After achieving M with all the with associated distance value i will fetch only those values which are less than or equal to provided threshold. Is it a proper way of doing it.?