Page 1 of 1

new ConvexHullShape produces ArgumentException

Posted: Thu Jun 16, 2016 8:13 am
by kapsl
Hi,
i created a mesh, that is basically a rectangle, that is behaving like a catenary. So its like a U-Shape in 3D. The position of this mesh and the mesh geometry is changing after the catenary laws. And I tried to create a ConvexHull of my Mesh like in the following code. The very strange thing is: It works well for maybe a dozen times. And then I get an error ArgumentExcpetion: Invalid distance - make sure the mesh is convex... But Helix displays the mesh perfectly - so it can't be completely wrong. Also I don't know if theres a better way of doing this. At the moment. Always the mesh changes its geometry, I remove The SpaceEntity and add it again, and recalculate the convex hull...
I read in other posts, that RemoveRedundantPoints() should help - but it doesn't?!

Thanks for your help!

lg manu

Code: Select all

List<Vector3> points = new List<Vector3>();

            // Generate convex hull data
            Point3DCollection p = ((MeshGeometry3D)((GeometryModel3D)collisionObject.RenderData.Content).Geometry).Positions;

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (Point3D actPoint in p)
                points.Add(new Vector3((float) actPoint.X, (float) actPoint.Y, (float) actPoint.Z));

            Vector3 computedCenter;

            ConvexHullHelper.RemoveRedundantPoints(points);
            ConvexHullShape shape = new ConvexHullShape(points, out computedCenter);

Re: new ConvexHullShape produces ArgumentException

Posted: Thu Jun 16, 2016 6:56 pm
by Norbo
That exception occurs late in the shape property calculation pipeline and implies the intermediate surface mesh generated for the convex hull was degenerate in some way that the convex hull generator failed to catch. RemoveRedundantPoints on the original point set can indeed sometimes help with removing degeneracies, but there are issues that it cannot help with.

My first guess is that there's something difficult about the original input point set other than redundant points- maybe near zero volume or something. It's hard to say for sure without an example point set; could you post a point set that leads to the failure so that I can investigate?

Re: new ConvexHullShape produces ArgumentException

Posted: Fri Jun 17, 2016 6:50 am
by kapsl
Hi,
and thanks for your quick answer!
Sure!

Ok this is the exact exception: Invalid distance. Ensure the mesh is convex, has consistent winding, and contains the passed-in center.
Computed Center is computedCenter = {{488,0125, 348,101, 182,2475}}

Points are
+ [0] {{0, 0, -0,001631813}} BEPUutilities.Vector3
+ [1] {{100, 0, -0,001631813}} BEPUutilities.Vector3
+ [2] {{200, 0, -0,001631813}} BEPUutilities.Vector3
+ [3] {{300, 0, -0,001631813}} BEPUutilities.Vector3
+ [4] {{400, 0, -0,001631813}} BEPUutilities.Vector3
+ [5] {{500, 0, -0,001631813}} BEPUutilities.Vector3
+ [6] {{600, 0, -0,001631813}} BEPUutilities.Vector3
+ [7] {{700, 0, -0,001631813}} BEPUutilities.Vector3
+ [8] {{800, 0, -0,001631813}} BEPUutilities.Vector3
+ [9] {{900, 0, -0,001631813}} BEPUutilities.Vector3
+ [10] {{1000, 0, -0,001631813}} BEPUutilities.Vector3
+ [11] {{1100, 0, -0,001631813}} BEPUutilities.Vector3
+ [12] {{0, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [13] {{100, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [14] {{200, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [15] {{300, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [16] {{400, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [17] {{500, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [18] {{600, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [19] {{700, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [20] {{800, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [21] {{900, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [22] {{1000, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [23] {{1100, 34,53656, -17,49872}} BEPUutilities.Vector3
+ [24] {{0, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [25] {{100, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [26] {{200, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [27] {{300, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [28] {{400, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [29] {{500, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [30] {{600, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [31] {{700, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [32] {{800, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [33] {{900, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [34] {{1000, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [35] {{1100, 69,07312, -30,31852}} BEPUutilities.Vector3
+ [36] {{0, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [37] {{100, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [38] {{200, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [39] {{300, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [40] {{400, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [41] {{500, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [42] {{600, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [43] {{700, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [44] {{800, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [45] {{900, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [46] {{1000, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [47] {{1100, 103,6097, -38,65808}} BEPUutilities.Vector3
+ [48] {{0, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [49] {{100, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [50] {{200, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [51] {{300, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [52] {{400, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [53] {{500, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [54] {{600, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [55] {{700, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [56] {{800, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [57] {{900, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [58] {{1000, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [59] {{1100, 138,1462, -42,64559}} BEPUutilities.Vector3
+ [60] {{0, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [61] {{100, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [62] {{200, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [63] {{300, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [64] {{400, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [65] {{500, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [66] {{600, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [67] {{700, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [68] {{800, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [69] {{900, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [70] {{1000, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [71] {{1100, 172,6828, -42,34236}} BEPUutilities.Vector3
+ [72] {{0, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [73] {{100, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [74] {{200, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [75] {{300, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [76] {{400, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [77] {{500, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [78] {{600, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [79] {{700, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [80] {{800, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [81] {{900, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [82] {{1000, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [83] {{1100, 207,2193, -37,74372}} BEPUutilities.Vector3
+ [84] {{0, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [85] {{100, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [86] {{200, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [87] {{300, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [88] {{400, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [89] {{500, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [90] {{600, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [91] {{700, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [92] {{800, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [93] {{900, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [94] {{1000, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [95] {{1100, 241,7559, -28,77899}} BEPUutilities.Vector3
+ [96] {{0, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [97] {{100, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [98] {{200, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [99] {{300, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [100] {{400, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [101] {{500, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [102] {{600, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [103] {{700, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [104] {{800, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [105] {{900, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [106] {{1000, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [107] {{1100, 276,2925, -15,31035}} BEPUutilities.Vector3
+ [108] {{0, 310,829, 2,86922}} BEPUutilities.Vector3
+ [109] {{100, 310,829, 2,86922}} BEPUutilities.Vector3
+ [110] {{200, 310,829, 2,86922}} BEPUutilities.Vector3
+ [111] {{300, 310,829, 2,86922}} BEPUutilities.Vector3
+ [112] {{400, 310,829, 2,86922}} BEPUutilities.Vector3
+ [113] {{500, 310,829, 2,86922}} BEPUutilities.Vector3
+ [114] {{600, 310,829, 2,86922}} BEPUutilities.Vector3
+ [115] {{700, 310,829, 2,86922}} BEPUutilities.Vector3
+ [116] {{800, 310,829, 2,86922}} BEPUutilities.Vector3
+ [117] {{900, 310,829, 2,86922}} BEPUutilities.Vector3
+ [118] {{1000, 310,829, 2,86922}} BEPUutilities.Vector3
+ [119] {{1100, 310,829, 2,86922}} BEPUutilities.Vector3
+ [120] {{0, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [121] {{100, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [122] {{200, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [123] {{300, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [124] {{400, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [125] {{500, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [126] {{600, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [127] {{700, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [128] {{800, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [129] {{900, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [130] {{1000, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [131] {{1100, 345,3656, 26,03918}} BEPUutilities.Vector3
+ [132] {{0, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [133] {{100, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [134] {{200, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [135] {{300, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [136] {{400, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [137] {{500, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [138] {{600, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [139] {{700, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [140] {{800, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [141] {{900, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [142] {{1000, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [143] {{1100, 379,9021, 54,55571}} BEPUutilities.Vector3
+ [144] {{0, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [145] {{100, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [146] {{200, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [147] {{300, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [148] {{400, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [149] {{500, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [150] {{600, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [151] {{700, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [152] {{800, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [153] {{900, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [154] {{1000, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [155] {{1100, 414,4387, 88,85712}} BEPUutilities.Vector3
+ [156] {{0, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [157] {{100, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [158] {{200, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [159] {{300, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [160] {{400, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [161] {{500, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [162] {{600, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [163] {{700, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [164] {{800, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [165] {{900, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [166] {{1000, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [167] {{1100, 448,9753, 129,4707}} BEPUutilities.Vector3
+ [168] {{0, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [169] {{100, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [170] {{200, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [171] {{300, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [172] {{400, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [173] {{500, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [174] {{600, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [175] {{700, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [176] {{800, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [177] {{900, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [178] {{1000, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [179] {{1100, 483,5118, 177,0208}} BEPUutilities.Vector3
+ [180] {{0, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [181] {{100, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [182] {{200, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [183] {{300, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [184] {{400, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [185] {{500, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [186] {{600, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [187] {{700, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [188] {{800, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [189] {{900, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [190] {{1000, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [191] {{1100, 518,0484, 232,2383}} BEPUutilities.Vector3
+ [192] {{0, 552,585, 295,972}} BEPUutilities.Vector3
+ [193] {{100, 552,585, 295,972}} BEPUutilities.Vector3
+ [194] {{200, 552,585, 295,972}} BEPUutilities.Vector3
+ [195] {{300, 552,585, 295,972}} BEPUutilities.Vector3
+ [196] {{400, 552,585, 295,972}} BEPUutilities.Vector3
+ [197] {{500, 552,585, 295,972}} BEPUutilities.Vector3
+ [198] {{600, 552,585, 295,972}} BEPUutilities.Vector3
+ [199] {{700, 552,585, 295,972}} BEPUutilities.Vector3
+ [200] {{800, 552,585, 295,972}} BEPUutilities.Vector3
+ [201] {{900, 552,585, 295,972}} BEPUutilities.Vector3
+ [202] {{1000, 552,585, 295,972}} BEPUutilities.Vector3
+ [203] {{1100, 552,585, 295,972}} BEPUutilities.Vector3
+ [204] {{0, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [205] {{100, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [206] {{200, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [207] {{300, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [208] {{400, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [209] {{500, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [210] {{600, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [211] {{700, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [212] {{800, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [213] {{900, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [214] {{1000, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [215] {{1100, 587,1215, 369,2016}} BEPUutilities.Vector3
+ [216] {{0, 621,658, 453,0528}} BEPUutilities.Vector3
+ [217] {{100, 621,658, 453,0528}} BEPUutilities.Vector3
+ [218] {{200, 621,658, 453,0528}} BEPUutilities.Vector3
+ [219] {{300, 621,658, 453,0528}} BEPUutilities.Vector3
+ [220] {{400, 621,658, 453,0528}} BEPUutilities.Vector3
+ [221] {{500, 621,658, 453,0528}} BEPUutilities.Vector3
+ [222] {{600, 621,658, 453,0528}} BEPUutilities.Vector3
+ [223] {{700, 621,658, 453,0528}} BEPUutilities.Vector3
+ [224] {{800, 621,658, 453,0528}} BEPUutilities.Vector3
+ [225] {{900, 621,658, 453,0528}} BEPUutilities.Vector3
+ [226] {{1000, 621,658, 453,0528}} BEPUutilities.Vector3
+ [227] {{1100, 621,658, 453,0528}} BEPUutilities.Vector3
+ [228] {{0, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [229] {{100, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [230] {{200, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [231] {{300, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [232] {{400, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [233] {{500, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [234] {{600, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [235] {{700, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [236] {{800, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [237] {{900, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [238] {{1000, 690,7311, 657,9588}} BEPUutilities.Vector3
+ [239] {{1100, 690,7311, 657,9588}} BEPUutilities.Vector3

Re: new ConvexHullShape produces ArgumentException

Posted: Fri Jun 17, 2016 5:47 pm
by Norbo
I couldn't reproduce the exception. A few things:
1) Are you using the latest version (changeset 11b068a840bb)?
2) Could you re-export the pointset, but formatted such that it can be directly copy pasted into C#? I'd like to eliminate transcription/parsing issues as possible confounders.
3) Note that a convex hull's collision cost increases linearly with the number of points in it, so generally, it's a good idea to have as few as possible.
4) As a last resort workaround, you can use the overload of the ConvexHullShape that takes a ConvexShapeDescription. It would require that you specify all the properties yourself, but the constructor won't do anything that has the chance of failing.

Re: new ConvexHullShape produces ArgumentException

Posted: Mon Jun 20, 2016 9:00 am
by kapsl
Ok, I integrated the latest version, instead of the nuget project. But error is still the same

It sais (with a different point set than in the last post) In InertiaHelper distance = -9.51 line 565

normal: {{0, -0,02549793, -0,9996749}}
fromCenterToPlain: {{-73,4003, -451,0835, 21,0283}}

But I think, I now found out the problem: Because I exported the point that made problems and tried to build the convex hull again, with this point. And as you said... Suddenly it worked. So i tried to round the float in the vector3 to whole numbers, and suddenly it worked?!

Re: new ConvexHullShape produces ArgumentException

Posted: Mon Jun 20, 2016 8:07 pm
by Norbo
It sounds like there's just some really tiny numerical issue throwing it off, and rounding gets around it. It could be that using RemoveRedundantPoints with a higher cellSize (default parameter value is 0.001) on the original set could help.

While that behavior implies a difficult input dataset, this should really be classified as a bug in the convex hull generator. It shouldn't be so fragile. I'm not too surprised given how old that particular part of the code is- it's something I should revisit at some point (another item on the very long BEPUphysics v2.0 todo list).