Skip to content
Prev 24091 / 29559 Next

igraph and spatial

In this example, I generate a bezier line with random curvature within a
specific range :

from = mst.bh[i, 1] # coordinates of the source node
to = mst.bh[i, 2] # coordinates of the target node

d = sqrt((coords[from, 1] - coords[to, 1])^2 + (coords[from, 2] -
coords[to, 2])^2) # the distance bewteen the two nodes

midpoint = c((coords[from, 1] + coords[to, 1])/2 + ifelse(runif(1,-1,1) >
0, 1, -1) * runif(1,0,d/3),
                 (coords[from, 2] + coords[to, 2])/2 + ifelse(runif(1,-1,1)
b = bezier(t=t <- seq(0, 1, length=100), p=rbind(coords[from, ], midpoint,
coords[to, ]))

rowname = paste(from, to, sep="_")
l = makeLineFromCoords(b, rowname)

2016-02-25 11:55 GMT+01:00 Mathieu Rajerison <mathieu.rajerison at gmail.com>: