Learn R Programming

geometry (version 0.1)

convhulln: Compute smallest convex hull that encloses a set of points

Description

Returns an index matrix to the points of simplices (triangles) that form the smallest convex simplicial complex of a set of input points in N-dimensional space.

Usage

convhulln(p, options = "Tv")

Arguments

p
An n-by-dim matrix. The rows of p represent n points in dim-dimensional space.
options
Optional options, see details below and Qhull documentation.

Value

  • An m-by-dim index matrix of which each row defines a dim-dimensional triangle. The indices refer to the rows in p. If the option "FA" is provided, then the output is a list with entries $hull containing the matrix mentioned above, and $area and $vol with the area and volume of the hull described by the matrix.

Details

This function interfaces the qhull library, and intends to be a port from Octave to R. The input n-by-dim matrix contains n points of dimension dim. If a second optional argument is given, it must be a string containing extra options for the underlying qhull command. The options always include "Qt". (See the Qhull documentation for the available options - refer to delaunayn.)

References

Barber, C.B., Dobkin, D.P., and Huhdanpaa, H.T., The Quickhull algorithm for convex hulls, ACM Trans. on Mathematical Software, Dec 1996. http://www.qhull.org

See Also

convex.hull, delaunayn, surf.tri, distmesh2d

Examples

Run this code
# example delaunayn
d = c(-1,1)
pc = as.matrix(rbind(expand.grid(d,d,d),0))
tc = delaunayn(pc)

# example tetramesh
library(rgl)
rgl.viewpoint(60)
rgl.light(120,60)
tetramesh(tc,pc, alpha=0.9)    # render tetrahedron mesh

# example convhulln
# ==> see also surf.tri to avoid unwanted messages printed to the console by qhull
ps = matrix(rnorm(3000),ncol=3)                     # generate poinst on a sphere
ps = sqrt(3) * ps / drop(sqrt((ps^2) %*% rep(1,3)))
ts.surf = t( convhulln(ps,"QJ") ) # see the qhull documentations for the options
rgl.triangles(ps[ts.surf,1],ps[ts.surf,2],ps[ts.surf,3],col="blue",alpha=.2)
for(i in 1:(8*360)) rgl.viewpoint(i/8)

Run the code above in your browser using DataLab