Search code examples
rdelaunayspatstat

Set maximum length for generating Delaunay graph in R


I was trying to generate Delaunay triangulation in R using the spatstat function 'delaunay'. However, I checked the documentation and seems there is no argument to set the maximum length. I noticed this post: How to set maximum length of triangle side in Delaunay triangulation in R? This seems done the same thing as I want, but as my point pattern is large so that I would prefer a simple and quick solution. Thank you!

Here is my code:

pts <- data.frame(readMat(paste('./TMA - Coordinates/HE_Rescaled_Coords/', core, 
'/HE.mat', sep = '')))
colnames(pts) <- c('x', 'y')
pts_ppp <- ppp(pts$x, pts$y, owin(poly = Region_HE))
delaunay_ppp <- delaunay(pts_ppp)  

I am also open to solutions using other functions from other packages. As long as it's fast.

Here is the region data: https://livejohnshopkins-my.sharepoint.com/:u:/g/personal/hmi1_jh_edu/EU5YeWiKzXlIohj7WIbfE_kB52Nbh2soXSNdHwQVukYnLA?e=t9tCf9

Here is the points data: https://livejohnshopkins-my.sharepoint.com/:u:/g/personal/hmi1_jh_edu/EaIuRF913rtBpg3VHvlp6TkB1FUomrgUc3eeUeHbVPJ50g?e=cwg1os


Solution

  • The Delaunay triangulation is a mathematically defined triangulation that does not involve the concept of a maximum segment length. If you want to constrain the maximum length of the segments in the triangulation, then it's not a Delaunay triangulation any more, and the algorithm for computing the Delaunay triangulation is not applicable.

    You will have to specify what you want to happen when you impose a limit on the segment length. Should the algorithm just delete the edges which are too long? Delete the triangles that have an edge which is too long? If you delete stuff then the result is no longer a triangulation of the original points. Do you want to produce a different triangulation?

    If X is your point pattern, then

    Dtess <- delaunay(X)
    Dnet <- delaunayNetwork(X)
    

    give the Delaunay triangulation as a tessellation Dtess and as a network Dnet. To remove edges from Dnet that are longer than lmax:

    len <- lengths_psp(as.psp(Dnet))
    Net <- thinNetwork(Dnet, retainedges = (len <= lmax))
    

    To remove triangles from Dtess that have at least one edge longer than lmax:

    hypotenuse <- function(p) { max(lengths_psp(edges(p))) }
    h <- sapply(tiles(Dtess), hypotenuse)
    Tess <- Dtess[h <= lmax]