-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request for area and volume calculations #2
Comments
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 |
Great! Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: