How to generate footprint of 3D geometry

My end goal is to obtain the centroid of the footprint polygon from a 3D geometry (e.g. a building). Once I have the footprint, it's trivial to use OpenLayers.Geometry.Polygon and then call getCentroid(). The problem is generating this footprint for a 3D geometry.

So far I've tried to use all vertices and construct a polygon out of that, but since they're not in order I don't see anything and the centroid is not correct. I had success by creating an OpenLayers.Geometry.LineString out of all the points and finding the centroid of that. However, it seems this method may give incorrect results for a set of geometries in an OpenLayers.Geometry.Collection.

Is there a simple algorithm (ray tracing?) for finding the footprint of an arbitrary 3D geometry? Perhaps I can work with all the vertices flattened to zero elevation by determining a suitable order?

Hi,

What about projecting all vertices on the base plane and get the convex
hull?

Hi Guillaume,

Thanks for pointing me in the right direction, I believe that’s exactly what I was hoping for. I’ll post my solution shortly.

I ended up using an existing JavaScript library and contributed a bit to it: