as.mesh3d.ashape3d: Convert alpha-shape surface of a cloud of points to RGL mesh...

View source: R/ashape3d.R

as.mesh3d.ashape3dR Documentation

Convert alpha-shape surface of a cloud of points to RGL mesh object


The alphashape3d::ashape3d function computes the 3D α-shape of a cloud of points. This is an approximation to the visual outline of the cloud. It may include isolated points, line segments, and triangular faces: this function converts the triangular faces to an RGL tmesh3d object.


## S3 method for class 'ashape3d'
                   alpha = x$alpha[1], 
                   tri_to_keep = 2L,
                   col = "gray", 
                   smooth = FALSE, normals = NULL,
                   texcoords = NULL, ...)



An object of class "ashape3d".


Which alpha value stored in x should be converted?


Which triangles to keep. Expert use only: see triang entry in Value section of ashape3d for details.


The surface colour.


Whether to attempt to add normals to make the surface look smooth. See the Details below.

normals, texcoords

Normals and texture coordinates at each vertex can be specified.


Additional arguments to pass to use as material3d properties on the resulting mesh.


Edelsbrunner and Mucke's (1994) α-shape algorithm is intended to compute a surface of a general cloud of points. Unlike the convex hull, the cloud may have voids, isolated points, and other oddities. This function is designed to work in the case where the surface is made up of simple polygons.

If smooth = TRUE, this method attempts to orient all of the triangles in the surface consistently and add normals at each vertex by averaging the triangle normals. However, for some point clouds, the α-shape will contain sheets of polygons with a few solid polyhedra embedded. This does not allow a consistent definition of "inside" and outside. If this is detected, a warning is issued and the resulting mesh will likely contain boundaries where the assumed orientation of triangles changes, resulting in ugly dark lines through the shape. Larger values of alpha in the call to alphashape3d::ashape3d may help.

Methods for plot3d and persp3d are also defined: they call the as.mesh3d method and then plot the result.


A "mesh3d" object, suitable for plotting.


Duncan Murdoch


Edelsbrunner, H., Mucke, E. P. (1994). Three-Dimensional Alpha Shapes. ACM Transactions on Graphics, 13(1), pp.43-72.

Lafarge, T. and Pateiro-Lopez, B. (2017). alphashape3d: Implementation of the 3D Alpha-Shape for the Reconstruction of 3D Sets from a Point Cloud. R package version 1.3.


if (requireNamespace("alphashape3d", quietly = TRUE)) {
  n <- 400    # 1000 gives a nicer result, but takes longer
  xyz <- rbind(cbind(runif(n), runif(n), runif(n)),
               cbind(runif(n/8, 1, 1.5), 
                     runif(n/8, 0.25, 0.75), 
                     runif(n/8, 0.25, 0.75)))
  ash <- suppressMessages(alphashape3d::ashape3d(xyz, alpha = 0.2))
  m <- as.mesh3d(ash, smooth = TRUE)
  mfrow3d(1, 2, sharedMouse = TRUE)
  plot3d(xyz, size = 1)
  plot3d(m, col = "red", alpha = 0.5)
  points3d(xyz, size = 1)

rgl documentation built on June 10, 2022, 9:05 a.m.