qhull minimal example

The qhull library has a central point with a few samples to start from when you want to use it in your code. Most interestingly, the developers invite you to call the qconvex program as an external application in case you want to calculate the convex hull of a point set. This may be the easy way for a few calls but will lead to resource wasting in case you want to do many calls. Of course, the developers tell you to use the C++ interface instead of the C interface. But on the same page, they tell you to be careful with the C++ bindings, as they are new and experimental. In case you are as confused as I am, here is the shortest way I know of to get the area and volume of a convex hull.

#include <iostream>
extern "C" {
    #include <qhull/qhull_a.h>

using namespace std;

int main(void) {
    int numpoints = 4;
    coordT points[] = {0,0,0, 1,0,0, 0,1,0, 0,0,1};
    int dim = 3;
    char flags[25];
    sprintf (flags, "qhull s FA");

    qh_new_qhull(dim, numpoints, points, 0, flags, NULL, NULL);
    qh_getarea(qh facet_list);
    cout << qh totvol << endl;
    cout << qh totarea << endl;

    return 0;

You may also like...

6 Responses

  1. Javier says:

    Hi Guido,
    I'm also very confused on how to use such interface, I'm also new at qhull.
    My query is the following:

    I have a data structure holding vertex positions of a 3D set. How can I load it onto qhull and then access the facets?

    Thank you very much

    • Guido says:

      Hi Javier,

      as far as I recall, this should work along the lines of this example (defines just for illustration purposes):

      #define NUM_POINTS 42
      #define DIMENSION 3
      double vertex_positions[NUM_POINTS*DIMENSION]
      char flags[25];
      sprintf (flags, "qhull s FA");
      qh_new_hull(DIMENSION, NUM_POINTS, vertex_positions, 0, flags, NULL, NULL);
      facets = qh facet_list;

      If your question is on reading the input from a data file, then please clarify. Typically, iostream is the easiest way on C++.

  2. Qhull-Newbie says:


    I'm totally new to qhull and it's very confusing to me. Do you know some good tutorial or similar to get started?


  3. Shekar Mantha says:

    I try this example and I get a linker error _qh_qh undefined. I am linking with libqhullstatic_r.a.

    Where is _qh_qh defined? I think it is because of these lines:

    qh facetlist
    qh totvol;

Leave a Reply

Your email address will not be published.