tessellation
tessellation copied to clipboard
Request for area and volume calculations
It is possible to include an output for the surface area and volume of the convex 3D hull of a Voronoi cell? That could be very useful, for example, in astronomy, where the inverse of the Voronoi cell volume is a proxy for the local density.
Thanks.
Hello @Dailer
I never saw a non-convex Voronoï cell. Does that exist? If I'm right, the convex hull of the cell is nothing but the cell.
I would use the cxhull package to get the volume and the area.
library(tessellation)
# take the vertices of a bounded Voronoï cell
d <- delaunay(centricCuboctahedron())
v <- voronoi(d)
vcell <- Filter(isBoundedCell, v)[[1]]
vertices <- cellVertices(vcell)
# compute its triangulated convex hull
library(cxhull)
hull <- cxhull(vertices, triangulate = TRUE)
# then you have the volume:
hull$volume
# get the vertices of all triangles
trgls <- TrianglesXYZ(hull)
# compute the area of these triangles
crossProduct <- function(v, w) {
c(
v[2L] * w[3L] - v[3L] * w[2L],
v[3L] * w[1L] - v[1L] * w[3L],
v[1L] * w[2L] - v[2L] * w[1L]
)
}
triangleArea <- function(A, B, C) {
v <- B - A
w <- C - A
sqrt(c(crossprod(crossProduct(v, w)))) / 2
}
ntrgls <- nrow(trgls) / 3
area <- 0
for(i in 1:ntrgls) {
A <- trgls[3*(i-1)+1, ]
B <- trgls[3*(i-1)+2, ]
C <- trgls[3*(i-1)+3, ]
area <- area + triangleArea(A, B, C)
}
Thank you very much!
I included it in the package now. Function cellVolume
.
Great! Thanks!