Generalizing the Convex Hull of a Sample: The R Package alphahull

Updated for alphahull 3.0.1

Beatriz Pateiro-López

Alberto Rodríguez-Casal

Departamento de Estatística e Investigación Operativa, Universidade de Santiago de Compostela, Spain. Centro de Investigación e Tecnoloxía Matemática de Galicia (CITMAga)

Abstract

This vignette presents the R package alphahull which implements the \(\alpha\)-convex hull and the \(\alpha\)-shape of a finite set of points in the plane. These geometric structures provide an informative overview of the shape and properties of the point set. Unlike the convex hull, the \(\alpha\)-convex hull and the \(\alpha\)-shape are able to reconstruct non-convex sets. This flexibility make them specially useful in set estimation. Since the implementation is based on the intimate relation of theses constructs with Delaunay triangulations, the R package alphahull also includes functions to compute Voronoi and Delaunay tesselations.

Keywords: set estimation, convexity, \(\alpha\)-convexity, \(\alpha\)-convex hull, \(\alpha\)-shape, R software

1. Introduction

The problem of reconstructing a set \(S\) from a finite set of points taken into it has been addressed in different fields of research. In computational geometry, for instance, the efficient construction of convex hulls for finite sets of points has important applications in pattern recognition, cluster analysis and image processing, among others. We refer the reader to (Preparata and Shamos 1985) for an introduction to computational geometry and its applications. From a probabilistic point of view, the set of points from which we try to reconstruct \(S\) is assumed to be non-deterministic. Thus, the term set estimation refers to the statistical problem of estimating an unknown set given a random sample of points whose distribution is closely related to it. Under this perspective, the target \(S\) might be, for example, a distribution support, its boundary or a level set. See (Cuevas and Fraiman 2009) for a survey of set estimation theory.

The support estimation problem is formally established as the problem of estimating the support of an absolutely continuous probability measure from independent observations drawn from it. The papers by (Geffroy 1964), (Rényi and Sulanke 1963), and (Rényi and Sulanke 1964) are the first works on support estimation. They deal with the convex case. When \(S\) is a convex support the natural estimator is the convex hull of the sample. See (Schneider 1988) for classical results on the convex hull estimator. However, when \(S\) is not convex, the convex hull of the sample is not an appropriate choice. In a more flexible framework, (Chevalier 1976) and (Devroye and Wise 1980) proposed to estimate the support (without any shape restriction) of an unknown probability measure by means of a smoothed version of the sample. The problem of support estimation is introduced by (Devroye and Wise 1980) in connection with a practical application, the detection of abnormal behaviour of a system, plant or machine. We refer to (Korostelëv and Tsybakov 1993) for a compilation of the most relevant theoretical results on the performance of such estimator. Anyhow, there are also approaches in-between the two aforementioned. In (Rodríguez-Casal 2007), the estimation of an \(\alpha\)-convex support is considered. The \(\alpha\)-convexity is a condition that affects the shape of the set of interest but which is much more flexible than convexity and therefore, it allows a wider range of applications. The \(\alpha\)-convex hull of the sample is the natural estimator when \(S\) is \(\alpha\)-convex. In this work we discuss the details on the implementation of this estimator.

Set estimation is also related to another interesting problem, the estimation of certain geometric characteristics of the set \(S\) such as the surface area (boundary length in \(\mathbb{R}^2\)). There are other statistical fields which also cope with problems regarding set measurements as, for example, the stereology. However, stereology focuses on the estimation of certain geometric characteristics of \(S\) without needing to reconstruct the set, see, e.g., (Baddeley and Jensen 2005), (Cruz-Orive 2001/02), whereas the primary object of interest of set estimation is the set itself. So in our framework, given a random sample of points in \(S\), the solution to the surface area estimation problem consists in defining an estimator that captures the shape of \(S\) and then estimating the surface area of \(S\) by means of the surface area of the estimator. (Bräker and Hsing 1998) studied the asymptotic properties of the boundary length of the convex hull of a random sample of points in \(\mathbb{R}^2\). They obtained the asymptotic normality of the boundary length of the convex hull estimator as well as its convergence rate in mean. In spite of the fact that the results are really significant, they are established on the assumption that the set of interest is convex, which may be too restrictive in practice. As mentioned before, more flexible estimators, such as the \(\alpha\)-convex hull, can be considered. The \(\alpha\)-shape, introduced by (Edelsbrunner et al. 1983), is another geometrical structure that serves to characterize the shape of a set. Its definition is based on a generalization of the convex hull. This vignette presents the R implementation ((R Core Team 2022)) of the \(\alpha\)-convex hull and \(\alpha\)-shape of a random sample of points in the plane with the package alphahull, see (Pateiro-López and Rodríguez-Casal 2010).

The document is organized as follows. In Section 2 we introduce some notation and describe the primary estimators under study, the \(\alpha\)-convex hull and the \(\alpha\)-shape of a random sample of points taken in the set of interest. The details on the implementation in R of the estimators are given in Section 3, along with the comprehensive description of the library alphahull. Section 4 concludes with a discussion of the contributions included in this document.

2. The \(\alpha\)-convex hull

Let \(S\) be a nonempty compact subset of the \(d\)-dimensional Euclidean space \(\mathbb{R}^d\), equipped with the norm \(\left\|\cdot\right\|\). Assume that we are given a random sample \(\mathcal{X}_n=\{X_1,\ldots,X_n\}\) from \(X\), where \(X\) denotes a random variable in \(\mathbb{R}^d\) with distribution \(P_X\) and support \(S\). The problem is to find a suitable estimator of \(S\) based on the sample. It seems natural that, in order to properly define such estimator, we should impose some geometric restriction on \(S\). As we have already commented, assuming convexity considerably limits the family of sets to estimate. So we focus on a more flexible shape condition, named \(\alpha\)-convexity.

We denote by \(\mathring{B}(x,r)\) and \({B}(x,r)\) the open and closed ball with center \(x\) and radius \(r\), respectively. Given \(A\subset\mathbb{R}^d\), \(A^c\) and \(\partial{A}\) will denote the complement and boundary of \(A\), respectively.

A set \(A\subset \mathbb{R}^d\) is said to be \(\alpha\)-convex, for \(\alpha>0\), if \(A=C_\alpha(A),\) where

\[C_\alpha(A)=\bigcap_{\{\mathring{B}(x,\alpha):\ \mathring{B}(x,\alpha)\cap A=\emptyset\}}{\left(\mathring{B}(x,\alpha)\right)^c}\]

is called the \(\alpha\)-convex hull of \(A\). Therefore, if \(A\) is \(\alpha\)-convex any point of \(A^c\) can be separated from \(A\) by means of an open ball of radius \(\alpha\). Note that the definition of the \(\alpha\)-convex hull given by (1) reminds us of the definition of the convex hull, but replacing the open balls of radius \(\alpha\) with half-spaces. Regarding the relation between convexity and \(\alpha\)-convexity, it can be proved that, if \(A\) is convex and closed, then it is also \(\alpha\)-convex for all \(\alpha>0\). If the interior of the convex hull is not empty then the reciprocal is also true, see (Walther 1999).

Using the same ideas as in the convex case, an estimator for an \(\alpha\)-convex support can be defined. Assume that \(S\) is \(\alpha\)-convex for some \(\alpha>0\). Then it seems reasonable to consider an estimator fulfilling this shape restriction. So, given a sample \(\mathcal{X}_n\subset S\), the natural estimator of \(S\) is the smallest \(\alpha\)-convex set which contains \(\mathcal{X}_n\), that is, the \(\alpha\)-convex hull of the sample, \(C_\alpha(\mathcal{X}_n)\), see Figure 1.

What can we say about the performance of \(C_\alpha(\mathcal{X}_n)\) as a support estimator? Like in other contexts, in order to evaluate a set estimator, we need certain measure of the distance between the estimator and the target \(S\). Thus, the performance of a set estimator is usually evaluated through either the Hausdorff distance, \(d_H\), or the distance in measure, \(d_\mu\), where \(\mu\) stands for the Lebesgue measure. We refer to (Edgar 1990) for a discussion on metrics between sets. (Rodríguez-Casal 2007) proved that, if \(S\) is \(\alpha\)-convex and standard with respect to \(P_X\), then \(d_H(S,C_\alpha(\mathcal{X}_n))=O((\log n/n)^{1/d})\) almost surely. A Borel set \(A\) is said to be standard with respect to a Borel measure \(\nu\) if there exists \(\varepsilon_0>0\) and \(\delta>0\) such that \(\nu(B(x,\varepsilon)\cap A)\geq \delta\mu(B(x,\varepsilon))\), for all \(x\in A\), \(0<\varepsilon\leq\varepsilon_0\). The standardness condition prevents the set \(S\) from being too spiky, see (Cuevas and Fraiman 1997) for more details. Although the family of \(\alpha\)-convex sets is much wider than the family of convex sets, \(C_\alpha(\mathcal{X}_n)\) achieves the same convergence rates as the convex hull of \(\mathcal{X}_n\) in the convex case, see (Dümbgen and Walther 1996). Moreover, if \(S\) belongs to Serra’s regular model, that is, if \(S\) is morphologically open and closed with respect to a compact ball of radius \(\alpha\) (see (Serra 1984)), then \(d_H(S,C_\alpha(\mathcal{X}_n))=O((\log n/n)^{2/(d+1)})\) almost surely. Again, the \(\alpha\)-convex hull is able to achieve the same convergence rate as the convex hull when \(S\) belongs to the Serra’s regular model.

Figure 1. In pink, \(\alpha\)-convex hull of a set of points in the plane for some \(\alpha>0\).

(Edelsbrunner et al. 1983) defined in \(\mathbb{R}^2\) a similar construct, the \(\lambda\)-hull of a finite set of points in the plane, for an arbitrary \(\lambda\in\mathbb{R}\). Following their terminology, \(C_\alpha(\mathcal{X}_n)\) equals the \(\lambda\)-hull of \(\mathcal{X}_n\) for \(\lambda=-1/\alpha\) and it can be computed in time \(O(n\log n)\) using \(O(n)\) space. The algorithm, described in Section 3, is based on the closed relationship that exists between \(\lambda\)-hulls and Delaunay triangulations. The Delaunay triangulation of a finite set of points contains, as subgraphs, various structures that have important applications in pattern recognition, cluster analysis, etc. See (Aurenhammer and Klein 2000) for a survey. The \(\alpha\)-shape is one of those subgraphs, derived from a straightforward generalization of the convex hull. For \(\alpha>0\), the \(\alpha\)-shape of \(\mathcal{X}_n\) is defined as the straight line graph connecting \(\alpha\)-neighbour points. Two points \(X_i,X_j\in\mathcal{X}_n\) are \(\alpha\)-neighbour if there exists an open ball of radius \(\alpha\) with both points on its boundary and which contains no sample points, see Figure 2. The definition of \(\alpha\)-shape can be extended to arbitrary real \(\alpha\) and higher dimensions, see (Edelsbrunner and Mücke 1994). The \(\alpha\)-shape is an approach to formalize the intuitive notion of shape for spatial point sets. The value of the parameter \(\alpha\) controls the shape of the estimator. For sufficiently large \(\alpha\), the \(\alpha\)-shape is identical to the boundary of the convex hull of the sample. As \(\alpha\) decreases, the shape shrinks until that, for sufficiently small \(\alpha\), the \(\alpha\)-shape is the empty set, see Figure 3. As with the \(\alpha\)-convex hull, the \(\alpha\)-shape of \(n\) points in the plane can be determined in time \(O(n\log n)\) and space \(O(n)\), see (Edelsbrunner et al. 1983). The description of the algorithm and the details of its implementation in R are given in Section 3.

Figure 2. In blue, \(\alpha\)-shape of a set of points in the plane for some \(\alpha>0\). Two points are \(\alpha\)-neighbours if there exists an open ball of radius \(\alpha\) with both points on its boundary and which contains no sample points.

Figure 3. Influence of the parameter \(\alpha\) on the \(\alpha\)-shape. From left to right, \(\alpha\)-shape of a random sample of size \(n=300\) on the annulus with outer radius \(0.5\) and inner radius \(0.25\) for \(\alpha=0.02,0.25,1\).

3. Implementation

The R package alphahull consists of three main functions: delvor, ashape, and ahull. The implementation of the \(\alpha\)-convex hull and of the \(\alpha\)-shape is based on the intimate relation of theses constructs with Delaunay triangulations. The function delvor described in Subsection 3.1 computes the Delaunay triangulation and the Voronoi diagram of a given sample of points in the plane. Based on the information provided by the function delvor, the function ashape described in Subsection 3.2 constructs the \(\alpha\)-shape for a given value of \(\alpha>0\). Finally, the function ahull described in Subsection 3.3 constructs the \(\alpha\)-convex hull. The R package alphahull also includes plot functions for the different objects and some other auxiliary functions which are described throughout this section.

3.1. Voronoi diagram and Delaunay triangulation

The Voronoi diagram of a finite sample of points \(\mathcal{X}_n=\{X_1,\ldots, X_n\}\) in \(\mathbb{R}^2\) is a covering of the plane by \(n\) regions \(V_i\) where, for each \(i\in\{1,\ldots, n\}\), the cell \(V_i\) consists of all points in \(\mathbb{R}^2\) which have \(X_i\) as nearest sample point. That is, \(V_i=\{x\in\mathbb{R}^2:\ \left\|x-X_i\right\|\leq \left\|x-X_j\right\| \text{ for all } X_j\in\mathcal{X}_n\}.\) We denote the Voronoi Diagram of \(\mathcal{X}_n\) by \(VD(\mathcal{X}_n)\). The Voronoi cells are closed and convex. Furthermore, \(V_i\) is unbounded if and only if \(X_i\) lies on the boundary of the convex hull of \(\mathcal{X}_n\). Otherwise \(V_i\) is a nonempty convex polygon. Two sample points \(X_i\) and \(X_j\) are said to be Voronoi neighbours if the cells \(V_i\) and \(V_j\) share a common point.

A triangulation of \(\mathcal{X}_n\) is a planar graph with vertex set \(\mathcal{X}_n\) and straight line edges that partition into triangles the convex hull of the nodes \(\mathcal{X}_n\). The Delaunay triangulation of \(\mathcal{X}_n\), denoted by \(DT(\mathcal{X}_n)\), is defined as the straight line dual to \(VD(\mathcal{X}_n)\). That is, there exists a Delaunay edge connecting the sample points \(X_i\) and \(X_j\) if and only if they are Voronoi neighbours, see Figure 4. In other words, each circumcentre of a Delaunay triangle coincides with a Voronoi cell vertex. The Delaunay triangulation was introduced by (Voronoi 1908) and extended by (Delaunay 1934), to whom it owes its name. A complete overview over the existing literature on these geometric constructions can be found in (Okabe et al. 2000). We also refer to the survey by (Aurenhammer 1991) for more details on the properties of the Delaunay triangulations and the Voronoi diagrams and their multiple applications.

Figure 4. There is a one-to-one correspondence between the Voronoi diagram (in green) and the Delaunay triangulation (in red).

From the computational viewpoint, efficient methods for the computation of Delaunay triangulations and Voronoi diagrams have been developed. (Aurenhammer and Klein 2000) presented a review of algorithms, from the earliest intuitive methods to more efficient representations of these geometric structures. For example, the incremental insertion process by (Green and Sibson 1978), the Divide and Conquer method by (Shamos and Hoey 1975) or the plane-sweep technique by (Fortune 1987) are the basis of a large class of worst-case optimal algorithms for computing the whole Voronoi diagram in the plane. Of course, these techniques can also be applied to the computation of the Delaunay triangulation. See for example the efficient incremental algorithm by (Lawson 1977). Both the Voronoi diagram and the Delaunay triangulation of \(n\) points can be computed in \(O(n\log n)\) time and linear space. Furthermore, by the duality between the Voronoi diagram and the Delaunay triangulation, either tessellation is easily obtained from a representation of the other in \(O(n)\) time.

Currently, there are several libraries available in R that compute the Delaunay triangulation or the Voronoi diagram of a given set of points. See the packages deldir by (Turner 2021) or geometry by (Habel et al. 2022), among others. These libraries differ on the implemented algorithms and the data structures that store the information. For example, the package deldir computes the Delaunay triangulation and the Voronoi diagram of a planar point set according to the second iterative algorithm of (Lee and Schachter 1980). Unfortunately, this package does not return the kind of data structure we need in order to compute the \(\alpha\)-shape and the \(\alpha\)-convex hull. The function deldir computes the triangulation of a set of points enclosed in a finite rectangular window. In consequence, the endpoints of the Voronoi edges outside that window are discarded. This fact does not appear to be a problem unless we need to know all the Voronoi edges, as in our case. Note that, in principle, the location of the furthest Voronoi vertex is unknown and enlarging the window size to ensure that the information is complete has a considerable computational cost. Our package alphahull computes the Delaunay triangulation and the Voronoi diagram with respect to the whole plane. For each edge of the Delaunay triangulation, the corresponding segment in the Voronoi diagram is obtained by connecting the circumcentres of the two neighbouring triangles that share that edge. For those edges of the Delaunay triangulation that lie on the boundary of the convex hull, the corresponding Voronoi edges are semi-infinite.

The Delaunay triangulation is computed using the function delaunayn from package geometry. The corresponding Voronoi diagram is constructed directly from the Delaunay triangulation by computing the circumcentres of the triangles and identifying their adjacency relationships. This approach allows us to obtain the primal and dual geometric structures without restricting the computation to a finite rectangular window.

The output of the function delvor is a list with three components. The first component, mesh, stores the primal and dual information. For each edge of the Delaunay triangulation, mesh contains the indices ind1, ind2 and the coordinates (x1, y1), (x2, y2) of the sample points that form the edge, the coordinates of the endpoints of the corresponding segment in the Voronoi diagram (mx1, my1), (mx2, my2), and indicators identifying the endpoints of Voronoi edges that represent unbounded extremes. Specifically, bp1 = 1 if (mx1, my1) is a dummy node, and similarly for bp2.

The second component, x, stores the sample points. The third component, tri.obj, contains the Delaunay triangulation and associated geometric information, including triangle vertices, adjacency relationships, circumcircle information, and convex hull indices. Although the triangulation is now computed using geometry, this component retains a structure compatible with the triSht objects previously returned by interp, in order to preserve backward compatibility with existing code and dependent packages.

As an illustration, we have applied the function delvor to a given set of \(n=5\) points. The result is assigned to the object dv and printed out.

x <- c(0.905, 0.606, 0.458, 0.988, 0.744)
y <- c(0.763, 0.937, 0.095, 0.259, 0.731) 
dv <- delvor(x,y)
dv
## $mesh
##      ind1 ind2    x1    y1    x2    y2       mx1       my1        mx2
## [1,]    1    2 0.905 0.763 0.606 0.937 0.7916732 0.9121597  1.2875222
## [2,]    1    4 0.905 0.763 0.988 0.259 0.8737869 0.4990254  1.8500226
## [3,]    1    5 0.905 0.763 0.744 0.731 0.8737869 0.4990254  0.7916732
## [4,]    2    3 0.606 0.937 0.458 0.095 0.2692467 0.5621847 -1.0855467
## [5,]    2    5 0.606 0.937 0.744 0.731 0.2692467 0.5621847  0.7916732
## [6,]    3    4 0.458 0.095 0.988 0.259 0.6578897 0.3874175  1.0370101
## [7,]    3    5 0.458 0.095 0.744 0.731 0.6578897 0.3874175  0.2692467
## [8,]    4    5 0.988 0.259 0.744 0.731 0.6578897 0.3874175  0.8737869
##             my2 bp1 bp2
## [1,]  1.7642220   0   1
## [2,]  0.6597944   0   1
## [3,]  0.9121597   0   0
## [4,]  0.8003194   0   1
## [5,]  0.9121597   0   0
## [6,] -0.8377887   0   1
## [7,]  0.5621847   0   0
## [8,]  0.4990254   0   0
## 
## $x
##       [,1]  [,2]
## [1,] 0.905 0.763
## [2,] 0.606 0.937
## [3,] 0.458 0.095
## [4,] 0.988 0.259
## [5,] 0.744 0.731
## 
## $tri.obj
## $n
## [1] 5
## 
## $x
## [1] 0.905 0.606 0.458 0.988 0.744
## 
## $y
## [1] 0.763 0.937 0.095 0.259 0.731
## 
## $nt
## [1] 4
## 
## $trlist
##      i1 i2 i3 j1 j2 j3 k1 k2 k3
## [1,]  5  4  3  0  2  3  6  7  8
## [2,]  5  2  3  0  1  4  4  7  5
## [3,]  1  5  4  1  0  4  8  2  3
## [4,]  1  5  2  2  0  3  5  1  3
## 
## $cclist
##              x         y         r     area     ratio
## [1,] 0.6578897 0.3874175 0.3542088 0.145088 0.4593401
## [2,] 0.2692467 0.5621847 0.5038743 0.073342 0.1617105
## [3,] 0.8737869 0.4990254 0.2658135 0.041900 0.2613487
## [4,] 0.7916732 0.9121597 0.1873275 0.018791 0.2646572
## 
## $nchull
## [1] 4
## 
## $chull
## [1] 1 2 3 4
## 
## $narcs
## [1] 8
## 
## $arcs
##      from to
## [1,]    1  2
## [2,]    1  4
## [3,]    1  5
## [4,]    2  3
## [5,]    2  5
## [6,]    3  4
## [7,]    3  5
## [8,]    4  5
## 
## $call
## delvor(x = x, y = y)
## 
## attr(,"class")
## [1] "triSht"
## 
## attr(,"class")
## [1] "delvor"

The plot of the previous Delaunay triangulation and Voronoi diagram is displayed in Figure 5. This graph is produced using the function plot.delvor (S3 method for class ‘delvor’). The arguments are the same as those of the function plot.deldir from package deldir.

plot(dv, main = "Delaunay triangulation and Voronoi diagram",col = 1:3, xlab = "x-coordinate", ylab = "y-coordinate",xlim = c(-0.5, 1.5), ylim = c(-0.5, 1.5), number = TRUE)

Figure 5. Plot of the Delaunay triangulation (red) and Voronoi diagram (green) of a uniform random sample of size \(n=5\) on the unit square. The dashed green lines correspond to the unbounded Voronoi edges.

3.2. The \(\alpha\)-shape

For the construction of the \(\alpha\)-shape of a finite sample of points \(\mathcal{X}_n\), the package alphahull implements the algorithm by (Edelsbrunner et al. 1983), see Table 1.

Table 1. Algorithm for computing the \(\alpha\)-shape

  1. Construct the Voronoi diagram and Delaunay triangulation of \(\mathcal{X}_n\).
  2. Determine the \(\alpha\)-extremes of \(\mathcal{X}_n\).
  3. Determine the \(\alpha\)-neighbours of \(\mathcal{X}_n\).
  4. Output the \(\alpha\)-shape.

The algorithm relies on the notion of \(\alpha\)-extreme point and \(\alpha\)-neighbour. A sample point \(X_i\) is termed \(\alpha\)-extreme if there exists an open ball of radius \(\alpha\) with \(X_i\) on its boundary and which contains no sample points. Finding the \(\alpha\)-extreme points is not a difficult task once the Delaunay triangulation and the Voronoi diagram are determined. Note that, if the sample points \(X_i\) lies on the convex hull of \(\mathcal{X}_n\), then \(X_i\) is \(\alpha\)-extreme for all \(\alpha>0\). If \(X_i\) does not lie on the convex hull we only need to compute the distances from \(X_i\) to the vertexes of the Voronoi cell \(V_i\). Then, \(X_i\) is \(\alpha\)-extreme for all \(\alpha\) satisfying \(0<\alpha\leq \max\{\left\|X_i-v\right\|,\ v\text{ vertex of } V_i\}\). Finding the \(\alpha\)-neighbour points is, however, trickier. Consider an edge of the Delaunay triangulation connecting the sample points \(X_i\) and \(X_j\) and its dual edge of the Voronoi diagram. The points \(X_i\) and \(X_j\) are \(\alpha\)-neighbours for all \(\alpha\) satisfying \(\alpha_{\min}\leq\alpha\leq \alpha_{\max}\), where \(\alpha_{\min}\) and \(\alpha_{\max}\) are determined from the position of \(X_i\) and \(X_j\) with respect to the vertexes of the dual Voronoi edge.

The function ashape, included in the library alphahull, computes the \(\alpha\)-shape of a given sample \(\mathcal{X}_n\) for a given value of \(\alpha>0\). The output of the function ashape is a list with six components. The components x and alpha store the input information whereas the component delvor.obj stores the output object from the function delvor, see Subsection 3.1. The indexes of the \(\alpha\)-extremes are given by the component alpha.extremes. The \(\alpha\)-neighbours connections are given by the first two columns of the matrix edges. The structure of edges is that of matrix mesh returned by the function delvor. Note that the \(\alpha\)-shape is a subgraph of the Delaunay triangulation and, therefore, edges is a submatrix of mesh. The length of the \(\alpha\)-shape is stored in the component length. The function plot.ashape (S3 method for class ‘ashape’) produces a plot of the \(\alpha\)-shape. Graphic parameters can control the plot appearance. Moreover, the Delaunay triangulation and the Voronoi diagram can be added to the plot by specifying the argument wlines (wlines = "del" for the Delaunay triangulation, wlines = "vor" for the Voronoi diagram or wlines = "both" for both plots). Next, we show an example on how these functions work. We have applied the function ashape to a uniform random sample of size \(n=50\) on the unit square with \(\alpha=0.2\). The result is assigned to the object alphashape.

x<-matrix(runif(100),ncol=2)
alpha <- 0.2
alphashape <- ashape(x, alpha = alpha)
names(alphashape)
## [1] "edges"          "length"         "alpha"          "alpha.extremes"
## [5] "delvor.obj"     "x"

A plot of the \(\alpha\)-shape may be obtained as follows. The result is displayed in Figure 6.

plot(alphashape, col = c(4, 1), xlab = "x-coordinate", ylab = "y-coordinate", main = expression(paste(alpha, "-shape")))

Figure 6. Plot of the \(\alpha\)-shape of a uniform random sample of size \(n=50\) on the unit square for \(\alpha=0.2\).

Also the Delaunay triangulation can be plotted by specifying the argument wlines as in the following code. The result is displayed in Figure 7.

plot(alphashape, wlines = "del", col = c(4, 1, 2), xlab = "x-coordinate", ylab = "y-coordinate")

Figure 7. Plot of the \(\alpha\)-shape (in blue) and Delaunay triangulation (in red) of a uniform random sample of size \(n=50\) on the unit square for \(\alpha=0.2\). The \(\alpha\)-shape is a subgraph of the Delaunay triangulation.

3.3. The \(\alpha\)-convex hull

Recall the definition of the \(\alpha\)-convex hull given in Equation (1). By DeMorgan’s law, the complement of \(C_\alpha(\mathcal{X}_n)\) can be written as the union of all open balls of radius \(\alpha\) which contain no point of \(\mathcal{X}_n\), that is,

\[C_\alpha(\mathcal{X}_n)^c=\bigcup_{\{\mathring{B}(x,\alpha):\ \mathring{B}(x,\alpha)\cap \mathcal{X}_n=\emptyset\}}{\mathring{B}(x,\alpha)}.\]

Therefore, in order to compute the complement of the \(\alpha\)-convex hull of a sample of points we should identify all those balls of radius \(\alpha\) that do contain no point of the sample. Fortunately, the problem simplifies thanks to the following lemma by (Edelsbrunner et al. 1983).

Lemma 1. Let \(\mathring{B}(x,r)\) be an open ball which does not contain any point of a sample \(\mathcal{X}_n\). Either \(\mathring{B}(x,r)\) lies entirely outside the convex hull of \(\mathcal{X}_n\) or there is an open ball which contains \(\mathring{B}(x,r)\) but no points of \(\mathcal{X}_n\) and which has its centre on an edge of \(VD(\mathcal{X}_n)\).

Therefore, we only have to consider appropriate balls centered on edges of \(VD(\mathcal{X}_n)\). For the implementation we have considered the two following situations. First, if \(X_i\) and \(X_j\) are two sample points such that the corresponding Voronoi cells \(V_i\) and \(V_j\) share a common closed line segment \([a,b]\), then it follows from the duality between the \(VD(\mathcal{X}_n)\) and \(DT(\mathcal{X}_n)\) that the union of open balls with centres on the edge \([a,b]\) which do not contain any point of a sample is equal to \(\mathring{B}(a,\left\|a-X_i\right\|)\cup \mathring{B}(b,\left\|b-X_i\right\|)\). Second, if \(X_i\) and \(X_j\) are two sample points such that the corresponding Voronoi cells \(V_i\) and \(V_j\) share a common semi-infinite line segment \([a,+\infty)\), then the union of open balls with centres on the edge \([a,+\infty)\) which do not contain any point of a sample can be written as \(\mathring{B}(a,\left\|a-X_i\right\|)\cup H(X_i,X_j),\) where \(H(X_i,X_j)\) denotes the open halfplane defined by the straight line through \(X_i\) and \(X_j\). It can be shown that, for each edge of the Voronoi diagram, the union of open balls with centres on it and radius \(\alpha\) which do not contain any point of \(\mathcal{X}_n\) can be written as the union of a finite number of open balls or halfplanes. As a consequence, the complement of the \(\alpha\)-convex hull of \(n\) points can be expressed as the union of \(O(n)\) open balls and halfplanes, see Lemma 6 by (Edelsbrunner et al. 1983). The package alphahull implements the algorithm in Table 2.

Table 2. Algorithm for computing the \(\alpha\)-convex hull

  1. Construct the Voronoi diagram and Delaunay triangulation of \(\mathcal{X}_n\).
  2. Determine the union of open balls and halfplanes that form \(C_\alpha(\mathcal{X}_n)^c\).
  3. Output the \(\alpha\)-convex hull.

The function ahull, included in the library alphahull, computes the \(\alpha\)-convex hull of a given sample \(\mathcal{X}_n\) for a given value of \(\alpha>0\). The output of the function ahull is a list with six components. Information about the open balls and halfplanes that define the complement of the \(\alpha\)-convex hull is stored in the component complement. For each row \(i\), complement[i, ] contains the information relative to an open ball or halfplane of the complement. The first three columns are assigned to the characterization of the ball or halfplane \(i\). Thus, if the row \(i\) refers to an open ball, complement[i, 1:3] contains the center and radius of the ball. If the row \(i\) refers to a halfplane, complement[i, 1:3] determines its equation. For the halfplane \(y>a+bx\), complement[i, 1:3] = (a, b, -1). In the same way, for the halfplane \(y<a+bx\), complement[i, 1:3]=(a, b, -2), for the halfplane \(x>a\), complement[i, 1:3]=(a, 0, -3) and for the halfplane \(x<a\), complement[i, 1:3] = (a, 0, -4). On the other hand, the component arcs stores the boundary of the \(\alpha\)-convex. Note that \(\partial C_\alpha(\mathcal{X}_n)\) is formed by arcs of balls of radius \(\alpha\) (besides possible isolated sample points). These arcs are determined by the intersections of some of the balls that define the complement of the \(\alpha\)-convex hull. The extremes of an arc can be written as \(c+rA_\theta(v)\) and \(c+rA_{-\theta}(v)\) where \(c\) and \(r\) represent the center and radius of the arc, respectively, and \(A_\theta(v)\) represents the clockwise rotation of angle \(\theta\) of a unitary vector \(v\), see Figure 8. Thus, the structure of the matrix arcs is as follows. For each arc of the boundary, the first two columns (c1, c2) correspond to the coordinates of the center \(c\). The third column r corresponds to the radius \(\alpha\). The next two columns (v.x, v.y) correspond to the coordinates of the unitary vector \(v\) whereas the angle \(\theta\) is stored in the sixth column theta. Finally, the indices of the end points of each arc are stored in the last two columns, end1 and end2. For isolated points in the boundary of the \(\alpha\)-convex hull, columns 3 to 6 of the matrix arcs are equal to zero. The component xahull consists on a 2-column matrix with the coordinates of the original set of points besides possible new end points of the arcs in the boundary of the \(\alpha\)-convex hull. The component alpha stores the input information and the component ashape.obj stores the output object from the function ashape (see Subsection 3.2) which is invoked during the computation of the \(\alpha\)-convex hull. Finally, the boundary length of the \(\alpha\)-convex hull is stored in the component length.

Figure 8. The extremes of an arc can be written as \(c+rA_\theta(v)\) and \(c+rA_{-\theta}(v)\), where \(A_\theta(v)\) represents the clockwise rotation of angle \(\theta\) of the unitary vector \(v\).

The function plot.ahull (S3 method for class ‘ahull’) produces a plot of the \(\alpha\)-convex hull. As with plot.ashape and plot.delvor some graphic parameters can control the plot appearance. The \(\alpha\)-shape can be added to the plot by specifying the argument do.shape = TRUE. Moreover, the Delaunay triangulation and the Voronoi diagram can be added to the plot by specifying the argument wlines (wlines = "del" for the Delaunay triangulation, wlines = "vor" for the Voronoi diagram or wlines = "both" for both plots). As an example, we have applied the function ahull to a uniform sample of size \(n=200\) on the annulus with outer radius \(0.5\) and inner radius \(0.25\). The result is assigned to the object alphahull.

n <- 200
theta<-runif(n,0,2*pi)
r<-sqrt(runif(n,0.25^2,0.5^2))
x<-cbind(0.5+r*cos(theta),0.5+r*sin(theta))
alpha <- 0.15
alphahull <- ahull(x, alpha = alpha)
names(alphahull)
## [1] "arcs"       "xahull"     "length"     "complement" "alpha"     
## [6] "ashape.obj"
alphahull$complement[1:5,1:3]
##             c1         c2         r
## [1,] 1.0867465  0.3795279 0.1639325
## [2,] 1.0867465  0.3795279 0.1639325
## [3,] 0.4013818 -0.2591877 0.3195981
## [4,] 0.4013818 -0.2591877 0.3195981
## [5,] 0.2283141  1.0719837 0.1667204
alphahull$arcs[1:5,]
##                c1        c2    r       v.x        v.y      theta end1 end2
## [1,] -0.025249701 0.8545207 0.15 0.8290373 -0.5591933 0.33339505   22    6
## [2,]  0.003982932 0.9113902 0.15 0.8204514 -0.5717162 0.08100272    6  193
## [3,]  0.062719358 0.9680759 0.15 0.5483332 -0.8362599 0.08830695  193   30
## [4,]  0.103043890 0.9908292 0.15 0.5049636 -0.8631406 0.17057491   30  106
## [5,]  0.175444345 1.0241260 0.15 0.4295790 -0.9030293 0.28183360  106  118
alphahull$length
## [1] 4.939305

A plot of the \(\alpha\)-convex hull may be obtained as follows. The result is displayed in Figure 9.

plot(alphahull, col = c(6, rep(1, 5)), xlab = "x-coordinate",ylab = "y-coordinate", main = expression(paste(alpha, "-hull")))

Figure 9. Plot of the \(\alpha\)-convex hull of a uniform random sample of size \(n=200\) on the annulus with outer radius \(0.5\) and inner radius \(0.25\). The value of \(\alpha\) is \(0.15\).

The plot of the \(\alpha\)-convex hull together with some of the balls of radius \(\alpha\) that define its complement, see Equation (2), is displayed in the left-hand side of Figure 10. This plot is obtained by using the information of the component arcs as shown in the following code. The function arc included in the library plots an arc given its center, radius, initial angle and final angle.

plot(alphahull, col = c(6, rep(1, 5)), xlab = "x-coordinate", ylab = "y-coordinate", main = expression(paste(alpha, "-hull")))
warcs<- which(alphahull$arcs[,3]>0)
for (i in warcs) {
arc(alphahull$arcs[i, 1:2], alphahull$arcs[i,3], c(0,1), pi, col = "gray", lty = 2)
}

The relation between the \(\alpha\)-convex hull and the \(\alpha\)-shape is shown in the right-hand side of Figure 10. In order to plot both the \(\alpha\)-convex hull and the \(\alpha\)-shape, specify the parameter do.shape = TRUE as in the following code.

plot(alphahull, do.shape = TRUE, col = c(6, 4, rep(1, 4)), xlab = "x-coordinate", ylab = "y-coordinate", main = expression(paste(alpha, "-hull and ",alpha, "-shape")))

Figure 10. Left: plot of the \(\alpha\)-convex hull and balls defining the complement. Right: plot of the \(\alpha\)-convex hull (in pink) and \(\alpha\)-shape (in blue).

Once \(C_\alpha(\mathcal{X}_n)^c\) is constructed we can decide whether a given point \(p\in\mathbb{R}^2\) belongs to the \(\alpha\)-convex hull or not, by checking if it belongs to any of the open balls or halfplanes that form the complement of the \(\alpha\)-convex hull. The function inahull returns a logical value specifying whether \(p\) belongs to \(C_\alpha(\mathcal{X}_n)^c\). The function areahull returns the area of the \(\alpha\)-convex hull. The idea behind this function is that, by joining the end points of adjacent arcs in the boundary of the \(\alpha\)-convex hull, we can define polygons that help us to determine the area of the estimator.

4. Conclusions

In this document we have described the implementation in R of the \(\alpha\)-convex hull and of the \(\alpha\)-shape of a random sample of points in the plane. The package alphahull is the result of that implementation, which is based on efficient algorithms presented by (Edelsbrunner et al. 1983). The \(\alpha\)-convex hull and the \(\alpha\)-shape generalize the notion of convex hull and serve to characterize the shape of an unknown set based on random sample of points taken into it. The results obtained by (Rodríguez-Casal 2007) on the behaviour of the \(\alpha\)-convex hull estimator give us the theoretical basis for using this geometrical construct as a support estimator.

Version 3.0.1. This vignette updates the presentation in (Pateiro-López and Rodríguez-Casal 2010) to reflect the implementation of alphahull 3.0.1. Whereas earlier versions used the interp package for Delaunay triangulation, version 3.0.1 uses geometry::delaunayn() (Qhull) and revises the construction of Voronoi edges, including the outward orientation of unbounded Voronoi rays. To preserve backward compatibility, the tri.obj component in objects returned by delvor() retains a structure compatible with the triSht objects previously provided by interp, including triangle connectivity, circumcircle information, and convex hull indices. These implementation changes do not alter the mathematical definitions of the \(\alpha\)-convex hull or the \(\alpha\)-shape.

Aurenhammer, Franz. 1991. “Voronoi Diagrams - a Survey of a Fundamental Geometric Data Structure.” ACM Comput. Surv. 23 (3): 345–405.
Aurenhammer, Franz, and Rolf Klein. 2000. “Voronoi Diagrams.” In Handbook of Computational Geometry. North-Holland.
Baddeley, Adrian, and Eva B. Vedel Jensen. 2005. Stereology for Statisticians. Vol. 103. Monographs on Statistics and Applied Probability. Chapman & Hall/CRC, Boca Raton, FL.
Bräker, H., and T. Hsing. 1998. “On the Area and Perimeter of a Random Convex Hull in a Bounded Convex Set.” Probab. Theory Related Fields 111 (4): 517–50.
Chevalier, Jacques. 1976. “Estimation Du Support Et Du Contour Du Support d’une Loi de Probabilité.” Ann. Inst. H. Poincaré Sect. B (N.S.) 12 (4): 339–64.
Cruz-Orive, Luis M. 2001/02. “Stereology: Meeting Point of Integral Geometry, Probability, and Statistics.” Math. Notae 41 (2001/02): 49–98 (2003).
Cuevas, Antonio, and Ricardo Fraiman. 1997. “A plug-in Approach to Support Estimation.” Ann. Stat. 25 (6): 2300–2312.
Cuevas, Antonio, and Ricardo Fraiman. 2009. New Perspectives on Stochastic Geometry. Edited by W. S. Kendall and I. Molchanov. Oxford University Press.
Delaunay, B. N. 1934. “Sur la Sphére Vide.” Bull. Acad. Sci. URSS, VII. Ser. 1934 (6): 793–800.
Devroye, Luc, and Gary L. Wise. 1980. “Detection of Abnormal Behavior via Nonparametric Estimation of the Support.” SIAM J. Appl. Math. 38 (3): 480–88.
Dümbgen, Lutz, and Günther Walther. 1996. “Rates of Convergence for Random Approximations of Convex Sets.” Adv. In Appl. Probab. 28 (2): 384–93.
Edelsbrunner, Herbert, David G. Kirkpatrick, and Raimund Seidel. 1983. “On the Shape of a Set of Points in the Plane.” IEEE Trans. Inform. Theory 29 (4): 551–59.
Edelsbrunner, Herbert, and Ernst P. Mücke. 1994. “Three-dimensional Alpha Shapes.” ACM Trans. Graph. 13 (1): 43–72.
Edgar, Gerald A. 1990. Measure, Topology, and Fractal Geometry. Undergraduate Texts in Mathematics. Springer-Verlag.
Fortune, Steven. 1987. “A Sweepline Algorithm for Voronoi Diagrams.” Algorithmica 2: 153–74.
Geffroy, Jean. 1964. “Sur Un Problème d’estimation Géométrique.” Publ. Inst. Statist. Univ. Paris 13: 191–210.
Green, P. J., and R. Sibson. 1978. “Computing Dirichlet Tessellations in the Plane.” Computer J. 21: 168–73.
Habel, Kai, Raoul Grasman, Robert B. Gramacy, Pavlo Mozharovskyi, and David C. Sterratt. 2022. Geometry: Mesh Generation and Surface Tessellation. https://CRAN.R-project.org/package=geometry.
Korostelëv, A. P., and A. B. Tsybakov. 1993. Minimax Theory of Image Reconstruction. Vol. 82. Lecture Notes in Statistics. Springer-Verlag.
Lawson, C. L. 1977. “Software for \({\cal{C}}^1\) Surface Interpolation.” In Mathematical Software III, Proc. Symp., Madison 1977, 161-194.
Lee, D. T., and B. J. Schachter. 1980. “Two Algorithms for Constructing a Delaunay Triangulation.” Int. J. Comput. Inform. Sci. 9: 219–42.
Okabe, Atsuyuki, Barry Boots, Kokichi Sugihara, and Sung Nok Chiu. 2000. Spatial Tessellations. Concepts and Applications of Voronoi Diagrams. Wiley Series in Probability and Mathematical Statistics. Applied Probability and Statistics. Chichester: Wiley. xii, 671 p.
Pateiro-López, Beatriz, and Alberto Rodríguez-Casal. 2010. “Generalizing the Convex Hull of a Sample: The r Package Alphahull.” Journal of Statistical Software 34 (5): 1–28. https://doi.org/10.18637/jss.v034.i05.
Preparata, Franco P., and Michael Ian Shamos. 1985. Computational Geometry: An Introduction. Texts and Monographs in Computer Science. Springer-Verlag.
R Core Team. 2022. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. https://www.R-project.org/.
Rényi, A., and R. Sulanke. 1963. “Über Die Konvexe Hülle von \(n\) Zufällig Gewählten Punkten.” Z. Wahrscheinlichkeitstheorie Und Verw. Gebiete 2: 75–84 (1963).
Rényi, A., and R. Sulanke. 1964. “Über Die Konvexe Hülle von \(n\) Zufällig Gewählten Punkten. II.” Z. Wahrscheinlichkeitstheorie Und Verw. Gebiete 3: 138–147 (1964).
Rodríguez-Casal, Alberto. 2007. “Set Estimation Under Convexity Type Assumptions.” Annales de l’I.H.P.- Probabilités & Statistiques 43: 763–74.
Schneider, R. 1988. “Random Approximation of Convex Sets.” J. Microscopy 151: 211–27.
Serra, J. 1984. Image Analysis and Mathematical Morphology. Academic Press Inc. [Harcourt Brace Jovanovich Publishers].
Shamos, M. I., and D. Hoey. 1975. “Closest-Point Problems.” Proc. 16th IEEE Symp. Foundations of Comp. Science, 151–62.
Turner, Rolf. 2021. Deldir: Delaunay Triangulation and Dirichlet (Voronoi) Tessellation. https://CRAN.R-project.org/package=deldir.
Voronoi, G. 1908. “Nouvelles Applications Des Paramètres Continus à La Théorie Des Formes Quadratiques. Deuxiéme Mémoire. Recherches Sur Les Paralléloèdres Primitifs.” J. Reine Angew. Math., 198–287.
Walther, Guenther. 1999. “On a Generalization of Blaschke’s Rolling Theorem and the Smoothing of Surfaces.” Math. Methods Appl. Sci. 22 (4): 301–16.