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

Fails on certain combinations of vertices for seemingly no reason. #39

Open JamDoggie opened 4 years ago

JamDoggie commented 4 years ago

The convex hull generator seems to like to fail with certain combinations of 3D vertices at certain positions. This is just one example of vertices that cause this to happen.

https://pastebin.com/0wRDKFYB

interestingly enough, offsetting these vertices to another position seems to allow the convex huller to work just fine. I am running the latest version of the library, taken directly from the github master branch.

Error message: Failed to find initial simplex shape with non-zero volume. While data appears to be in 3 dimensions, the data is all co-planar (or collinear, co-hyperplanar) and is representable by fewer dimensions.

erictuvesson commented 4 years ago

I am having the same issue with Voronoi (which is using ConvexHull).

Dump:

static void Main()
{
    var vertices = new List<double[]>()
    {
        new [] {-0.525731086730957,0,0.8506507873535156},
        new [] {-0.4844416379928589,0.1312003880739212,0.8649293184280396},
        new [] {-0.40335533022880554,0,0.9150434136390686},
        new [] {-0.4338885545730591,0.25989192724227905,0.8626684546470642},
        new [] {-0.35822877287864685,0.13165538012981415,0.9243046045303345},
        new [] {-0.2732664942741394,0,0.9619383215904236},
        new [] {-0.30901697278022766,0.5,0.80901700258255},
        new [] {-0.23867692053318024,0.3861873745918274,0.8910065293312073},
        new [] {-0.3750385344028473,0.3836137354373932,0.8439114689826965},
        new [] {-0.1624598503112793,0.2628655731678009,0.9510565400123596},
        new [] {-0.3012588620185852,0.26408275961875916,0.9162441492080688},
        new [] {0.0,0.0,1.0},
        new [] {-0.13795222342014313,0,0.9904388785362244},
        new [] {-0.0822424665093422,0.13307112455368042,0.9876883625984192},
        new [] {-0.2201170176267624,0.13279248774051666,0.9663926362991333},
        new [] {0,0.8506507873535156,0.525731086730957},
        new [] {0.08108629286289215,0.7838429808616638,0.6156420111656189},
        new [] {-0.08108629286289215,0.7838429808616638,0.6156420111656189},
        new [] {0.1606220304965973,0.7020464539527893,0.6937804818153381},
        new [] {0,0.7112817168235779,0.7029070258140564},
        new [] {-0.1606220304965973,0.7020464539527893,0.6937804818153381},
        new [] {0.30901697278022766,0.5,0.80901700258255},
        new [] {0.15643446147441864,0.5192584991455078,0.8401778936386108},
        new [] {0.23708631098270416,0.6068251132965088,0.7586523294448853},
        new [] {0,0.525731086730957,0.8506507873535156},
        new [] {0.08114185184240341,0.6202395558357239,0.7802043557167053},
        new [] {-0.23708631098270416,0.6068251132965088,0.7586523294448853},
        new [] {-0.15643446147441864,0.5192584991455078,0.8401778936386108},
        new [] {-0.08114185184240341,0.6202395558357239,0.7802043557167053},
        new [] {0.525731086730957,0,0.8506507873535156},
        new [] {0.40335533022880554,0,0.9150434136390686},
        new [] {0.4844416379928589,0.1312003880739212,0.8649293184280396},
        new [] {0.2732664942741394,0,0.9619383215904236},
        new [] {0.35822877287864685,0.13165538012981415,0.9243046045303345},
        new [] {0.4338885545730591,0.25989192724227905,0.8626684546470642},
        new [] {0.0822424665093422,0.13307112455368042,0.9876883625984192},
        new [] {0.13795222342014313,0,0.9904388785362244},
        new [] {0.1624598503112793,0.2628655731678009,0.9510565400123596},
        new [] {0.2201170176267624,0.13279248774051666,0.9663926362991333},
        new [] {0.3750385344028473,0.3836137354373932,0.8439114689826965},
        new [] {0.23867692053318024,0.3861873745918274,0.8910065293312073},
        new [] {0.3012588620185852,0.26408275961875916,0.9162441492080688},
        new [] {-0.0823235809803009,0.3996070325374603,0.9129824638366699},
        new [] {0.0823235809803009,0.3996070325374603,0.9129824638366699},
        new [] {0,0.2664047181606293,0.9638612270355225}
    };

    VoronoiMesh.Create(vertices.Select(arr => new Vertex(arr)).ToList());
}

By making the distance between the points larger it seems to solve the issue. Must be some compare issues.

VoronoiMesh.Create(vertices.Select(arr => new Vertex(arr.Select(v => v * 1000).ToArray())).ToList());

Call Stack: image

derekatcoats commented 1 year ago

Hi - I get this issue using the Nuget package (1.1.19.1019), but using the code from Git works OK...