Chapter 21 Computational Geometry


ricebag
10-21-2009, 09:48 AM
Hi guys:

I am not very experienced with C++ so I might sound a bit foolish.

I want to use delaunay.h to find the convex hull of a set of points (section 21.7.3). Do I define a "Convexhull" structure and call the Convexhull constructor function (giving the function a vector input)?

It would be great if someone can provide a simple implementation code that uses the Convex hull constructor.

Thanks!

davekw7x
10-21-2009, 01:40 PM
... Do I define a "Convexhull" structure and call the Convexhull constructor function...

I think that you've almost got it:

Declare and populate a std::vector of Point<2> objects.

Use that vector as the argument to the constructor:

You can do something like:

Int n = how_many_points_you_have;
vector < Point<2> > pointvec(n); // A vector of that size
//
// Put Points into the vector with an assignment statement
for (Int i = 0; i < n; i++) {
Doub x, y;
//x = whatever, y = whatever
Point<2> p(x,y);
pointvec[i] = p; // Do this for i = 0, 1, ... , n-1
}
.
.
.
Convexhull hull(pointvec);
.
.
.


Or


vector < Point<2> > pointvec; //An empty vector

//
//
// Do stuff to put your Points into the vector by
// creating Points and using push_back().

// Probably some kind of loop that gets x and
// y values for each point and terminates when
// there are no more points
Doub x, y;
//x = whatever, y = whatever
//
Point<2> p(x,y)
pointvec.push_back(p);
.
.
.
Convexhull hull(pointvec);
.
.
.


Regards,

Dave

ricebag
10-21-2009, 07:22 PM
Hi Dave:

Thanks a lot, it works well!

Best,

Henry