Rqhull

Qhull in R


The geometry package intents to implement several geometry functions available in Octave and Matlab and the like, available in R. It merely ports those functions to R and makes available the qhull library (which also underlies the corresponding Matlab and Octave functions). Currently only part of the qhull library is accessible and no specific class for a Delaunay triangulation is specified.

The geometry package also implements a simple technique to refine a given mesh and generate high quality meshes and surface triangulations. A description of the technique and a number of examples can be found at the site of its inventors Per-Olof Persson and Gilbert Strang.

The Qhull library is documented online at www.qhull.org

A gzipped tar-ball with the sources, and a pre-compiled binary distribution for windows can be downloaded from CRAN. All original qhull sources are included in the distribution. The distribution is subject to this license. The non-qhull sources are subject to the GPL version 2 or higher.

Using the Qhull options

Qhull provides many options that you can use to your advantage. For instance you may request the volume of a convex hull and its surface area by specifying the 'FS' option. Currently the output is written to the console window, and cannot be accessed programmatically. However, Qhull has the option TO filename which can be used to write the output to a file which can then be parsed into R again. For instance, if you want to compute the volume of a convex hull of a set of points, if you have a matrix with 3 columns,
> ps <- matrix(rnorm(30),,3);

say, that might be something like
> x = convhulln(ps,"FS TO 'bla.txt'"); # use of the 'TO filename' option

This command created the text file 'bla.txt' that contains the requested output (i.e. the output specified by the Qhull options). For the Qhull option FS this is the following: [from the doc] "The first line consists of the number of integers ("0"). The second line consists of the number of reals ("2"), followed by the total facet area, and the total volume. Later versions of Qhull may produce additional integers or reals." You can then parse the text in the file according to your needs; in your case it will be something like
> qh.outp <- scan('bla.txt ');
> volume <- qh.outp[3];

Wish list for future releases

  • port __vonoroi__.cc
  • get rid of output to console in convhulln (specifying NULL as standard output handle gives wrong result)
  • more self explaining interface for qhull options (?)
  • quiet error output
  • Implement in C/Fortran
  • Translate other functions of the matlab mesh package of Per-Olof Persson (http://www-math.mit.edu/~persson/mesh/)
  • n-D interpolation with Delaunay triangulation

Contribute

If you have ideas for functions, or functions you made and think would be of value to include in the geometry package (take into account that the package is called geometry and restricts itself to functions directly related to computational geometry), you can e-mail me: rgrasman •at• uva •dot• nl, or you can fill out the form below.

No comments: