DesignEngrLab / MIConvexHull

A .Net fast convex hull library for 2, 3, and higher dimensions.
http://designengrlab.github.io/MIConvexHull/
MIT License
341 stars 60 forks source link

Question regarding output #3

Closed Bekwnn closed 7 years ago

Bekwnn commented 8 years ago

I was wondering if a contributor could tell me:

  1. Does the convex hull computation return one face containing all vertices lying on a plane, or would it potentially return multiple faces which lie on the same plane?
  2. Are vertices lying on the shell of the convex hull included in the convex hull? i.e., if a vertex lies in the center of a face, is it included or excluded?

Thank you for your time and for this project.

micampbell commented 8 years ago

These are good questions, and they are at the root of an issue that my co-developer and I have wrestled with for a long time. I would call the convex hull that excludes all internal vertices as the minimal convex hull, while one that includes all internal vertices the maximal convex hull. What is produced by MIConvexHull is not guaranteed to be either. Sorry for the bad news. The reason for doing this is speed and robustness. If you need either, you would need to post-process the results of this algorithm. At some point, we should provide this as a built in facility. What would happen, is that after this result is created, one would go back and consider how the vertices should be added or removed. One thing to realize is that in either case - minimal or maximal - it is not necessarily the case that there is a single tessellation that is the answer. Another thing to realize is that the (new) single tolerance that is accepted in the ConvexHull routine is the distance that a new vertex is above an existing plane to be considered for initiating new faces. Higher values produce convex hulls with fewer vertices and faces (toward or beyond the minimal) while a lower number produces something with more vertices and faces (like the maximal). Due to round-off error a value of exact zero - a new vertex exactly in the plane - is not recommended. This is true even for double precision. The default 1e-10 seems to works well without sacrificing accuracy.

Bekwnn commented 8 years ago

Thank you. I had one further question: looking at the calls to ConvexHull.Create<>(), I can't tell whether there's a method in this library which would return some sort of 2-dimensional array of indices, similar to triangle indexing although not necessarily triangular (but preferably ordered).

I'm hoping to keep a mapping from my input to the resulting output without having to do a full comparison of my input against the resulting output.

micampbell commented 8 years ago

There is not a facility to do that. Again, I agree it would be handy and it could also be done best as a post-processing step. A few LINQ calls could generate such a 2d array, but it would not be quick as it would require many calls to "IndexOf", but perhaps that is okay for you.