Skip to content

mesh_mesh_contact further development #61

@2twenity

Description

@2twenity

Describe the bug

Hi everybody! First of all I want to admit that the algorithm is not final and may have some bugs, I just want to share some examples that could be used for testing in the future and also I would be happy to contribute to the development of this python library because I came to the lack of this kind of functionality in python during my own research.

I've been following the mesh to mesh algorithm to analyze the adjacency of meshes.

world = Frame.worldXY()
interfaces: list[Contact] = []

a = meshes_lst[3]
b = meshes_lst[4]

for a_face in a.faces():
    a_points = a.face_coordinates(a_face)
    a_normal = a.face_normal(a_face)

    for b_face in b.faces():
        b_points = b.face_coordinates(b_face)
        b_normal = b.face_normal(b_face)
        
        frame = Frame(*bestfit_frame_numpy(a_points + b_points))

        if frame.zaxis.dot(a_normal) < 0:
            frame.invert()

        matrix = Transformation.from_change_of_basis(world, frame)

        a_projected = transform_points(a_points, matrix)
        b_projected = transform_points(b_points, matrix)

        p0 = ShapelyPolygon(a_projected)
        p1 = ShapelyPolygon(b_projected)

        intersection: ShapelyPolygon = p0.intersection(p1)
        area = intersection.area

        if hasattr(intersection, "exterior"):
            coords = [[x, y, 0.0] for x, y, _ in intersection.exterior.coords]

            if coords:
                points = transform_points(coords, matrix.inverted())[:-1]
                frame = Frame(centroid_polygon(points), frame.xaxis, frame.yaxis)

                interface = Contact(points=points, frame=frame, size=area)
                # print(interface)
                interfaces.append(interface)

and found out that there could be some projection error.

print(len(interfaces)) -> 64 # the algorithm found 64 interfaces between 2 non adjacent meshes
Image

To Reproduce

# mesh a data
a_faces = [0,1,2,3,4,5,6,7,8,9,10,11]
a_vertices = [[2.170565, 3.304107, 3.75],[2.170565, 3.304107, 3.45],[2.170565, 3.004107, 3.75],[2.411012, 3.304107, 3.75],[2.170565, 3.004107, 3.45],[2.411012, 3.304107, 3.45],[2.411012, 3.004107, 3.45],[2.411012, 3.004107, 3.75]]
# mesh b data
b_faces = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,841,842,843,844,845,846,847,848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,863,864,865,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,884,885,886,887,888,889,890,891,892,893,894,895,896,897,898,899,900,901,902,903,904,905,906,907,908,909,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998,999,1000,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,1017,1018,1019,1020,1021,1022,1023,1024,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051]

b_vertices = [[3.131992, 2.905101, 3.731112],[2.237268, 2.242159, 3.29624],[3.151452, 2.798892, 3.453961],[2.425021, 2.23359, 3.186387],[2.486012, 3.260958, 3.494725],[2.710112, 3.149756, 3.74599],[2.478776, 2.287122, 3.567651],[3.163793, 2.441346, 3.613142],[2.486012, 3.23007, 3.470657],[2.919987, 2.502993, 3.705345],[2.930864, 3.040243, 3.746957],[2.837124, 2.900281, 3.675474],[2.893786, 2.573329, 3.50677],[2.486012, 3.024764, 3.524037],[2.393955, 2.257427, 3.189871],[3.167073, 2.704428, 3.450284],[2.987048, 2.678942, 3.520523],[2.969868, 3.098056, 3.496649],[3.254912, 2.829248, 3.637752],[2.206523, 2.100109, 3.335627],[2.189051, 2.052524, 3.232395],[2.581057, 3.104339, 3.744821],[2.243955, 1.99762, 3.226928],[2.871745, 3.197861, 3.641494],[2.509732, 2.266096, 3.289293],[2.168955, 2.127524, 3.1766],[3.07056, 2.359606, 3.521796],[3.085159, 2.530132, 3.436664],[2.617961, 3.291192, 3.601407],[3.062498, 2.376043, 3.487136],[2.563981, 3.015189, 3.674225],[2.486012, 3.191853, 3.745173],[2.399413, 2.132359, 3.532658],[2.694603, 2.307803, 3.355994],[2.942788, 2.473427, 3.717437],[2.90917, 3.007885, 3.7517],[2.280132, 1.982635, 3.1766],[2.964317, 2.281748, 3.502808],[2.853957, 3.162587, 3.708382],[2.470944, 2.091197, 3.210753],[2.811817, 2.51326, 3.492121],[2.910294, 2.310605, 3.674869],[2.864802, 3.184181, 3.677534],[2.898004, 2.828697, 3.600172],[3.019484, 2.710114, 3.491034],[2.221366, 2.063882, 3.334827],[3.207794, 2.688736, 3.724236],[3.168328, 2.442342, 3.574259],[2.419047, 2.09972, 3.523551],[3.254137, 2.831445, 3.560138],[3.055405, 2.555756, 3.433824],[2.946084, 2.274833, 3.615972],[2.83801, 2.901375, 3.52548],[3.117199, 2.777536, 3.748672],[3.013017, 2.749226, 3.492557],[2.826353, 2.884097, 3.600287],[2.997579, 2.702286, 3.672197],[2.486012, 3.080074, 3.469543],[2.490697, 2.35564, 3.476025],[2.977266, 2.732114, 3.637329],[3.244999, 2.55423, 3.585198],[2.973456, 2.682408, 3.55713],[2.852125, 2.21371, 3.477675],[2.590019, 3.144618, 3.450245],[2.505961, 3.23007, 3.470657],[2.740292, 2.154973, 3.445236],[2.664692, 3.014074, 3.493823],[2.604275, 3.218291, 3.470924],[2.397084, 2.315669, 3.424988],[2.967763, 2.443233, 3.71956],[2.991135, 3.129888, 3.564257],[2.812502, 2.217933, 3.622339],[3.039201, 2.837654, 3.74524],[2.722023, 3.184134, 3.731312],[3.088087, 3.036413, 3.527771],[3.276945, 2.693518, 3.554769],[3.188468, 2.949067, 3.562931],[2.497566, 2.216845, 3.594964],[2.174066, 2.166346, 3.1766],[2.410114, 2.003299, 3.255114],[3.071989, 3.019098, 3.496485],[2.342326, 1.985738, 3.290576],[2.404308, 2.28944, 3.281796],[2.696478, 2.425791, 3.616506],[2.725943, 2.237522, 3.366572],[2.318955, 1.977524, 3.216495],[2.212889, 2.23359, 3.1766],[2.425021, 2.021458, 3.1766],[3.108661, 2.47638, 3.707703],[3.008836, 2.820691, 3.470208],[2.603258, 2.408208, 3.478205],[2.991985, 2.736113, 3.673514],[2.212889, 2.021458, 3.1766],[3.236343, 2.698937, 3.48814],[2.481369, 2.340252, 3.510897],[2.357778, 2.272412, 3.1766],[3.102532, 2.883501, 3.745823],[2.649583, 2.971759, 3.599512],[3.055579, 2.355074, 3.635541],[2.512585, 2.041588, 3.421161],[2.956156, 2.513936, 3.430742],[3.165008, 2.449937, 3.535967],[3.050918, 2.709674, 3.466803],[3.176133, 2.940798, 3.526646],[2.612512, 2.084255, 3.47564],[2.990677, 3.129321, 3.641899],[2.704422, 2.461342, 3.507549],[2.546219, 2.067755, 3.355817],[2.948069, 2.774328, 3.599532],[3.10154, 3.050523, 3.602953],[2.499195, 3.116362, 3.454827],[2.189051, 2.202524, 3.224299],[2.174066, 2.088701, 3.1766],[3.054452, 2.696639, 3.726282],[2.839949, 3.134551, 3.731936],[2.609, 3.247209, 3.707127],[2.655009, 2.368607, 3.383638],[2.507391, 3.259383, 3.706851],[2.553572, 2.120488, 3.567415],[2.40172, 2.260157, 3.214485],[2.828976, 2.888069, 3.639157],[2.437691, 2.025911, 3.237998],[2.981768, 2.704891, 3.63627],[2.486012, 3.283451, 3.675963],[2.740772, 2.933417, 3.599995],[2.486012, 3.047257, 3.705275],[3.072088, 2.350298, 3.55982],[2.635795, 2.106002, 3.404652],[2.492299, 3.004112, 3.598886],[2.504651, 2.361998, 3.439909],[2.318889, 2.284773, 3.360098],[2.486012, 3.078145, 3.729343],[2.486012, 3.259383, 3.706851],[2.393955, 2.257427, 3.1766],[2.732331, 3.213726, 3.707737],[2.402435, 2.007986, 3.380638],[2.189051, 2.052524, 3.1766],[2.913342, 2.38665, 3.408211],[2.60356, 2.265137, 3.320636],[2.587315, 2.389902, 3.552043],[2.486012, 3.048832, 3.493149],[3.226101, 2.568745, 3.511152],[2.332634, 2.282331, 3.243662],[2.651535, 2.976852, 3.560735],[2.983572, 2.801966, 3.493809],[2.672598, 2.176267, 3.613642],[3.045138, 2.752964, 3.728475],[2.931972, 2.539313, 3.448301],[2.734738, 2.141353, 3.481574],[3.097979, 3.046356, 3.641727],[3.131397, 2.691679, 3.74533],[2.868971, 2.947485, 3.471099],[3.069945, 2.865296, 3.450678],[2.747439, 3.256041, 3.602048],[2.874313, 3.202695, 3.60272],[2.808672, 3.069009, 3.451365],[2.619597, 2.229409, 3.320585],[2.588464, 3.142512, 3.750234],[2.761127, 2.973526, 3.494334],[2.742755, 2.937758, 3.638863],[2.509969, 3.299281, 3.562254],[3.02237, 2.699472, 3.702898],[2.976014, 2.707108, 3.597566],[2.21652, 2.212178, 3.31137],[2.280132, 2.272412, 3.1766],[2.95893, 2.300145, 3.468626],[2.663136, 3.012708, 3.705945],[3.14349, 2.589812, 3.733654],[2.243955, 2.257427, 3.1766],[2.772913, 2.267638, 3.666961],[2.50887, 3.283451, 3.675963],[2.823732, 3.101983, 3.746592],[2.973084, 2.909456, 3.746084],[2.306735, 1.991985, 3.306507],[3.240507, 2.553297, 3.624086],[2.997455, 2.601942, 3.458126],[2.495112, 3.048832, 3.493149],[2.43157, 2.009578, 3.353931],[2.393955, 1.99762, 3.203894],[2.495199, 2.177866, 3.23871],[2.430838, 2.235634, 3.204825],[2.274143, 2.20283, 3.428558],[2.724349, 2.136666, 3.519075],[2.635424, 2.390135, 3.409842],[3.226915, 2.556763, 3.660693],[2.459257, 2.246153, 3.247406],[2.95236, 2.776725, 3.638389],[3.000134, 2.941109, 3.45157],[2.591868, 2.340121, 3.611573],[3.175285, 2.596418, 3.458396],[2.486012, 3.299281, 3.562254],[2.656689, 2.991285, 3.524686],[2.809808, 2.463152, 3.667826],[3.038679, 2.639287, 3.72282],[3.13118, 2.909259, 3.471336],[3.151712, 2.447016, 3.649964],[2.867438, 2.945591, 3.730895],[2.477303, 2.316881, 3.542149],[3.141916, 2.61296, 3.444762],[2.503829, 3.194005, 3.455403],[2.370851, 2.24104, 3.508812],[3.066979, 2.348752, 3.598616],[2.910941, 3.010073, 3.451713],[2.73574, 2.204754, 3.385707],[3.263174, 2.688598, 3.668653],[3.029378, 2.425409, 3.436966],[2.280132, 1.982635, 3.222181],[2.937789, 2.635979, 3.59157],[2.954405, 2.631305, 3.515865],[2.723928, 3.185807, 3.471516],[2.733336, 2.333991, 3.674966],[2.686911, 3.078044, 3.45557],[2.486012, 3.228141, 3.730457],[2.487008, 2.293066, 3.306382],[2.791352, 3.03413, 3.456123],[2.561299, 3.000695, 3.637933],[3.107796, 2.60587, 3.740149],[2.798971, 2.487948, 3.639466],[2.281448, 2.127841, 3.447887],[2.828905, 2.20377, 3.589722],[2.494731, 3.047257, 3.705275],[2.746057, 3.251448, 3.563183],[2.244122, 2.032435, 3.329413],[2.911458, 2.842807, 3.675354],[2.602928, 3.216467, 3.730722],[2.486012, 3.298704, 3.639898],[3.216268, 2.820334, 3.492866],[2.614502, 3.271941, 3.526253],[2.529366, 2.233458, 3.280186],[2.563592, 2.325766, 3.348134],[3.008813, 2.671313, 3.488692],[2.887537, 2.9756, 3.746222],[3.071478, 3.016978, 3.708607],[2.973782, 2.912352, 3.456321],[2.564758, 3.016242, 3.524231],[2.384207, 2.168442, 3.533161],[3.009648, 2.816533, 3.729984],[2.639861, 2.129372, 3.3734],[2.463844, 2.166346, 3.184055],[2.697411, 3.112934, 3.750773],[2.942323, 2.636975, 3.552688],[2.968964, 2.681475, 3.596018],[2.264846, 2.26477, 3.279125],[2.374465, 2.205511, 3.525028],[3.025763, 2.966869, 3.746804],[2.929926, 2.289145, 3.648644],[2.486012, 3.304103, 3.601114],[3.205151, 2.564392, 3.692524],[2.740634, 2.176597, 3.412538],[2.655588, 2.990319, 3.674679],[2.684785, 3.076178, 3.745334],[2.544572, 2.197374, 3.279683],[2.343331, 2.033856, 3.424772],[2.561702, 3.00124, 3.56029],[2.554314, 2.160305, 3.287816],[2.928067, 2.862243, 3.494518],[3.261134, 2.696123, 3.518842],[2.745487, 3.250948, 3.640826],[2.775136, 3.001562, 3.470779],[2.75953, 2.972178, 3.706455],[2.492674, 3.009511, 3.560102],[2.513604, 2.181116, 3.594913],[3.136225, 2.482434, 3.471371],[2.981602, 2.48517, 3.422751],[2.595924, 3.180757, 3.745425],[2.486012, 3.116362, 3.454827],[2.273897, 2.165776, 3.441571],[2.500982, 3.152994, 3.749996],[2.952059, 2.61471, 3.664956],[3.282698, 2.691301, 3.593473],[2.693793, 2.445826, 3.582929],[2.542384, 2.346534, 3.373708],[3.026461, 2.969765, 3.457041],[2.889247, 2.977714, 3.456457],[2.575555, 3.070663, 3.469756],[2.699612, 3.114865, 3.450787],[2.480364, 2.214096, 3.239522],[2.486012, 3.009511, 3.560102],[2.584458, 2.298003, 3.330032],[2.971981, 2.731499, 3.598515],[2.494476, 2.069229, 3.276861],[2.486012, 3.152994, 3.749996],[2.448858, 2.052524, 3.192499],[2.696502, 2.457952, 3.545766],[2.318955, 1.977524, 3.1766],[2.212889, 2.23359, 3.218962],[2.31739, 2.059554, 3.439191],[2.948093, 2.324941, 3.440266],[2.631477, 2.193252, 3.329884],[2.882386, 2.579651, 3.543695],[2.49019, 2.042659, 3.453462],[2.297373, 2.278472, 3.261191],[3.050969, 2.996365, 3.47236],[2.493634, 3.024764, 3.524037],[3.192758, 2.951464, 3.601788],[2.865932, 3.185134, 3.527541],[2.503308, 3.191853, 3.745173],[3.240085, 2.559499, 3.546678],[2.38256, 2.298062, 3.457027],[2.58256, 3.106373, 3.455053],[2.95114, 3.070472, 3.732315],[2.486012, 3.02365, 3.674033],[2.297433, 2.264427, 3.386385],[2.345077, 2.296129, 3.332666],[2.752513, 2.419818, 3.411921],[2.806413, 3.067103, 3.75135],[2.964226, 2.787394, 3.524692],[2.749153, 2.950979, 3.675174],[3.176602, 2.938398, 3.676628],[2.704376, 2.399212, 3.644208],[2.468436, 2.167961, 3.198611],[3.127316, 2.70673, 3.445709],[3.218386, 2.814332, 3.704911],[2.463844, 2.088701, 3.1766],[2.888525, 2.337751, 3.69286],[3.157256, 2.923826, 3.707511],[2.463844, 2.166346, 3.1766],[3.091639, 2.693981, 3.740755],[3.101626, 2.888138, 3.45608],[2.793404, 2.239717, 3.648684],[2.486012, 3.11421, 3.744597],[2.510204, 3.304103, 3.601114],[2.812581, 2.325544, 3.385639],[3.025491, 2.580249, 3.441145],[2.174066, 2.088701, 3.232744],[2.982101, 3.116582, 3.677933],[3.087698, 2.708519, 3.451343],[2.425021, 2.23359, 3.1766],[3.240916, 2.823202, 3.673892],[2.973878, 2.676206, 3.634538],[2.626467, 2.090613, 3.439524],[3.154346, 2.790694, 3.74362],[2.976491, 2.734311, 3.559716],[2.507773, 3.260958, 3.494725],[3.087725, 3.034914, 3.677763],[2.948575, 2.882856, 3.730765],[2.827975, 2.498948, 3.459449],[2.752425, 2.299794, 3.675925],[3.050343, 2.993769, 3.732155],[2.638388, 2.159132, 3.347898],[2.850243, 2.919901, 3.706764],[2.841541, 2.260323, 3.416397],[2.493364, 3.02365, 3.674033],[2.793492, 2.359742, 3.384679],[2.987863, 2.66696, 3.670064],[2.78917, 3.032289, 3.745887],[3.114204, 2.786023, 3.448796],[2.844559, 2.401443, 3.699881],[2.82897, 2.291634, 3.396457],[2.50914, 3.284565, 3.525967],[2.973209, 2.619356, 3.483612],[2.841906, 3.136201, 3.472141],[2.741434, 3.23748, 3.526881],[2.479214, 2.04128, 3.300212],[2.800233, 2.519447, 3.529013],[2.941109, 2.628385, 3.629863],[2.486012, 3.194005, 3.455403],[3.171015, 2.68989, 3.739696],[2.911819, 2.844306, 3.525362],[3.038666, 2.368832, 3.668078],[2.373612, 2.272607, 3.485618],[2.448858, 2.202524, 3.1766],[2.829434, 2.888636, 3.561514],[2.448858, 2.202524, 3.184403],[2.869375, 2.450341, 3.415232],[3.132907, 2.458965, 3.682217],[2.878805, 2.568796, 3.620515],[2.280132, 2.272412, 3.206541],[2.709835, 2.141232, 3.555183],[3.079951, 2.764667, 3.743507],[2.486012, 3.284565, 3.525967],[2.501521, 3.155221, 3.450004],[2.969891, 2.595887, 3.694458],[2.212889, 2.021458, 3.230412],[2.174066, 2.166346, 3.228553],[3.154058, 2.463611, 3.500874],[2.357778, 2.272412, 3.194617],[2.374212, 2.297721, 3.305959],[2.750282, 2.951932, 3.525182],[2.468955, 2.127524, 3.185365],[2.717012, 2.455765, 3.470883],[2.675194, 2.340525, 3.365272],[2.980711, 2.708787, 3.558722],[2.610099, 3.248698, 3.495003],[2.368224, 2.276084, 3.227731],[2.509829, 3.298704, 3.639898],[2.594883, 2.087361, 3.510539],[2.851495, 2.921448, 3.494641],[3.017393, 2.38909, 3.69401],[2.993758, 3.13386, 3.603127],[2.568384, 3.038432, 3.705476],[2.496542, 3.078145, 3.729343],[2.416194, 2.324228, 3.391683],[2.486012, 3.155221, 3.450004],[2.633005, 2.237072, 3.641285],[2.957668, 2.268646, 3.57908],[2.318955, 2.277524, 3.200303],[2.949201, 2.885452, 3.47097],[2.453593, 2.204188, 3.199411],[2.372338, 2.016267, 3.404801],[2.532706, 2.148251, 3.585517],[2.716948, 2.367901, 3.664147],[2.438589, 2.323157, 3.359383],[3.239228, 2.688295, 3.700005],[2.932543, 2.354446, 3.419659],[2.560522, 2.995937, 3.599072],[2.597426, 3.182791, 3.455658],[3.070883, 2.860496, 3.750642],[3.20426, 2.70177, 3.464756],[2.569484, 3.039921, 3.493351],[2.457758, 2.020934, 3.326499],[2.968616, 3.096509, 3.708772],[2.855555, 3.163935, 3.49626],[3.203998, 2.581337, 3.481041],[2.462743, 2.312528, 3.330288],[2.243955, 2.257427, 3.212905],[2.50275, 2.139932, 3.245025],[2.448858, 2.052524, 3.1766],[2.794014, 2.517088, 3.567611],[2.485687, 2.253001, 3.585665],[2.712238, 3.151621, 3.456226],[2.486012, 3.004112, 3.598886],[2.204015, 2.176873, 3.323485],[2.652413, 2.204349, 3.632008],[2.993209, 2.414467, 3.711569],[2.866105, 2.368735, 3.701391],[2.441771, 2.072751, 3.506462],[2.557928, 2.124776, 3.304032],[2.692184, 2.154739, 3.587438],[3.112725, 2.505123, 3.449471],[3.239418, 2.827445, 3.523954],[2.574208, 3.068839, 3.729554],[2.711912, 2.272671, 3.356438],[2.458439, 2.055891, 3.222868],[2.357778, 1.982635, 3.210258],[2.999411, 2.938111, 3.751555],[2.849439, 2.233744, 3.444099],[2.617772, 2.403643, 3.442097],[2.189051, 2.202524, 3.1766],[2.87233, 3.198354, 3.563852],[2.468955, 2.127524, 3.1766],[3.038296, 2.842291, 3.455496],[2.531696, 2.050148, 3.387856],[2.200605, 2.138648, 3.331759],[3.037267, 2.66004, 3.463806],[2.891796, 2.419358, 3.406701],[2.952673, 3.072367, 3.472518],[3.176696, 2.575665, 3.71741],[2.901565, 2.832865, 3.561398],[2.927556, 2.860123, 3.70664],[2.616782, 3.28589, 3.640188],[2.733415, 2.441602, 3.438266],[2.502503, 2.102878, 3.258038],[2.963886, 2.271005, 3.540482],[2.498674, 3.11421, 3.744597],[2.497009, 3.080074, 3.469543],[2.463844, 2.088701, 3.188245],[2.296283, 2.091611, 3.447075],[3.259422, 2.83206, 3.598953],[3.020958, 2.54819, 3.729165],[3.070473, 2.645893, 3.447562],[3.188859, 2.803245, 3.728694],[2.673095, 3.041993, 3.730044],[3.009965, 2.654367, 3.700175],[2.900913, 2.529916, 3.684109],[2.825915, 3.103824, 3.456828],[2.393955, 1.99762, 3.1766],[3.042544, 2.760314, 3.468774],[2.910699, 2.55957, 3.474233],[2.982987, 3.117676, 3.52794],[2.574779, 2.09972, 3.541841],[3.156593, 2.92722, 3.495404],[2.993391, 2.573198, 3.716359],[3.050712, 2.522566, 3.732005],[3.106167, 2.629835, 3.441066],[2.743339, 2.938252, 3.561221],[2.586974, 2.368277, 3.584742],[2.675, 3.043665, 3.470249],[3.098166, 3.047132, 3.564085],[2.486012, 3.008934, 3.637746],[2.433316, 2.271851, 3.261825],[3.278001, 2.689623, 3.632317],[2.877276, 2.578105, 3.582491],[3.188711, 2.947825, 3.640568],[2.318955, 2.277524, 3.1766],[2.932574, 3.042357, 3.457192],[2.773179, 2.999911, 3.730574],[2.650966, 2.976352, 3.638377],[2.740334, 3.236515, 3.676874],[2.825358, 2.433647, 3.688433],[2.964695, 2.784994, 3.674674],[2.505494, 3.228141, 3.730457],[2.733887, 3.215092, 3.495615],[3.080626, 2.498073, 3.724685],[2.615695, 2.272204, 3.640842],[2.492535, 3.008934, 3.637746],[2.243955, 1.99762, 3.1766],[2.555167, 2.093209, 3.327226],[3.186265, 2.810595, 3.468993],[3.006577, 2.454975, 3.424874],[3.077057, 2.772865, 3.453848],[2.282171, 2.236478, 3.409735],[2.886867, 2.55236, 3.655175],[2.773004, 2.391897, 3.393644],[2.849416, 2.201584, 3.514838],[2.377586, 1.989597, 3.273047],[3.048452, 2.398487, 3.458202],[2.522281, 2.358892, 3.40501],[2.601664, 2.307352, 3.630707],[2.474354, 2.129421, 3.202479],[2.425021, 2.021458, 3.197836],[2.990487, 2.740357, 3.523575],[2.901378, 2.832089, 3.63904],[2.617184, 3.286435, 3.562546],[2.466037, 2.053288, 3.482556],[2.357778, 1.982635, 3.1766],[2.841496, 2.198194, 3.553055],[2.59287, 2.403522, 3.515706],[3.015135, 2.743225, 3.704602],[2.952117, 2.777967, 3.560752],[2.613725, 3.270888, 3.676248],[2.273239, 2.007913, 3.319753],[2.995538, 2.709812, 3.522386],[3.072047, 2.622745, 3.736454],[2.168955, 2.127524, 3.231433],[2.984235, 2.798572, 3.705916],[2.793584, 2.506344, 3.605284],[2.847607, 2.477488, 3.433224]]
print(mesh_a) -> #<Mesh with 8 vertices, 12 faces, 18 edges>
mesh_a.is_valid() -> True
mesh_a.is_trimesh() -> True
mesh_a.is_connected() -> True
mesh_a.is_manifold() -> True
print(mesh_b) -> #<Mesh with 528 vertices, 1052 faces, 1578 edges>
mesh_a.is_valid() -> True
mesh_a.is_trimesh() -> True
mesh_a.is_connected() -> True
mesh_a.is_manifold() -> True

Expected behavior

Meshes shouldn't be overlapping

During my own approach I've developed the following algorithm.

def check_triangle(face: List[List[float]]) -> bool:
    """Function for faces validation. Checks if 3 points lie on a same line"""
    face_point1 = Point(*face[0])
    face_point2 = Point(*face[1])

    line = Line(face_point1, face_point2)

    face_point3 = Point(*face[2])

    if face_point3.on_line(line):
        # print("Forms same line!!!!!!")
        return False

    # print("Form triangle")
    return True


def check_adjacent_meshes(mesh1: Mesh, mesh2: Mesh) -> bool:
    
    # print("Mesh1 data", mesh1.is_manifold(), mesh1.is_trimesh(), mesh1.is_connected(), mesh1.is_valid())
    # print("Mesh2 data", mesh2.is_manifold(), mesh2.is_trimesh(), mesh2.is_connected(), mesh2.is_valid())

    # Making bounding boxes to see if it's reasonable to check adjacency 
    mesh1_aabb = mesh1.aabb() 
    mesh2_aabb = mesh2.aabb()

    # check if aabb have overlaps
    if any(mesh1_aabb.contains_points(mesh2_aabb.points)) or any(mesh2_aabb.contains_points(mesh1_aabb.points)):
    
        for face1 in mesh1.faces():
            face1_vertices = [mesh1.vertex_coordinates(face) for face in mesh1.face_vertices(face1)]
            
            if check_triangle(face1_vertices):
            
                plane1 = mesh1.face_plane(face1)
                
                for face2 in mesh2.faces():
                    face2_vertices = [mesh2.vertex_coordinates(face) for face in mesh2.face_vertices(face2)]
    
                    if check_triangle(face2_vertices):
                        plane2 = mesh2.face_plane(face2)
                        
                        # Check if 2 faces are parallel
                        if plane1.is_parallel(plane2):
                        
                            face1_vertices = mesh1.face_vertices(face1)
                            random_point_of_a_first_plane = Point(*mesh1.vertex_coordinates(face1_vertices[0]))
                            
                            # Check if 2 faces have 1 shared point    
                            if plane2.contains_point(random_point_of_a_first_plane):
                
                                mesh1_face_coordinates = [mesh1.vertex_coordinates(face) for face in mesh1.face_vertices(face1)]
                                mesh1_polygon = ShapelyPolygon(mesh1_face_coordinates)
                                    
                                mesh2_face_coordinates = [mesh2.vertex_coordinates(face) for face in mesh2.face_vertices(face2)]
                                mesh2_polygon = ShapelyPolygon(mesh2_face_coordinates)
                                
                                # Intersection of Shapely polygons    
                                if mesh1_polygon.intersects(mesh2_polygon):
                                    return True        
    return False

This algorithm is less advanced, because has boolean output and doesn't consider clashes, but maybe could be useful during the development and tests.

# Test
check_adjacent_meshes(a, b) -> False

Desktop (please complete the following information):

  • iOS Sequoia 15.2 M4
  • Python version: 3.12
  • Python package manager: conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions