0
$\begingroup$

Given a triangulated MeshRegion surface consisting of over 3000 triangles, with flipped faces, can I easily and automatically flip those triangles using Mathematica?

For some unknown reason the function RepairMesh[mesh,"FlippedFaces"] returns a discrete set of points with no higher-dimensional cells. A small example meshtest1 is provided later. (There are other mesh defects which I'd like to keep. )

Here is a way (by hand) which will take a lot of time:

  1. FindMeshDefects[mesh, "FlippedFaces"]
  2. Copy the picture as input form and paste
  3. Obtain the indices of faces to be flipped (This takes time, as there are too many triangles)
  4. Use "For" to flip those faces in the triangle list
  5. Form another MeshRegion, with no such mesh defects.

MeshCoordinates[meshtest1] is

{{-0.3,0.1,1.1},{0.688272,0.405075,0.976093},{-0.270933,0.108973,1.09636},{-0.241866,0.117946,1.09271},{-0.2128,0.126918,1.08907},{-0.183733,0.135891,1.08542},{-0.154666,0.144864,1.08178},{-0.125599,0.153837,1.07813},{-0.0965322,0.16281,1.07449},{-0.0674653,0.171782,1.07085},{-0.0383985,0.180755,1.0672},{-0.00933169,0.189728,1.06356},{0.0197351,0.198701,1.05991},{0.048802,0.207674,1.05627},{0.0778688,0.216646,1.05262},{0.106936,0.225619,1.04898},{0.136002,0.234592,1.04534},{0.165069,0.243565,1.04169},{0.194136,0.252538,1.03805},{0.223203,0.26151,1.0344},{0.25227,0.270483,1.03076},{0.281337,0.279456,1.02711},{0.310403,0.288429,1.02347},{0.33947,0.297402,1.01982},{0.368537,0.306375,1.01618},{0.397604,0.315347,1.01254},{0.426671,0.32432,1.00889},{0.455738,0.333293,1.00525},{0.484804,0.342266,1.0016},{0.513871,0.351239,0.997959},{0.542938,0.360211,0.994314},{0.572005,0.369184,0.99067},{0.601072,0.378157,0.987026},{0.630139,0.38713,0.983381},{0.659205,0.396103,0.979737},{-0.3,0.1,1.1},{-5.76851*10^-7,-5.51777*10^-7,2.86239*10^-7},{-0.289996,0.0952455,1.06608},{-0.280043,0.0906219,1.0322},{-0.270142,0.0861266,0.998366},{-0.260293,0.0817573,0.964568},{-0.250498,0.0775114,0.93081},{-0.240757,0.0733868,0.89709},{-0.231071,0.0693809,0.863408},{-0.221441,0.0654916,0.829765},{-0.211867,0.0617164,0.79616},{-0.20235,0.0580533,0.762591},{-0.19289,0.0544998,0.72906},{-0.183489,0.051054,0.695566},{-0.174147,0.0477135,0.662107},{-0.164863,0.0444763,0.628685},{-0.155639,0.0413403,0.595298},{-0.146474,0.0383035,0.561946},{-0.13737,0.0353637,0.528629},{-0.128326,0.032519,0.495346},{-0.119342,0.0297674,0.462098},{-0.11042,0.0271071,0.428883},{-0.101558,0.024536,0.395702},{-0.0927572,0.0220524,0.362553},{-0.0840179,0.0196544,0.329437},{-0.0753399,0.0173402,0.296354},{-0.0667233,0.0151079,0.263302},{-0.0581682,0.012956,0.230282},{-0.0496745,0.0108825,0.197293},{-0.0412422,0.008886,0.164336},{-0.0328714,0.00696467,0.131409},{-0.0245619,0.00511693,0.0985119},{-0.0163136,0.00334118,0.0656452},{-0.00812657,0.00163587,0.0328081},{-1.2299*10^-6,-1.18584*10^-6,-1.51197*10^-6},{0.556348,-0.368154,-0.6328},{0.0414693,-0.0356004,-0.0318046},{0.0803371,-0.067552,-0.0627264},{0.116802,-0.0963467,-0.0928662},{0.151052,-0.122396,-0.122309},{0.18326,-0.146046,-0.151127},{0.213585,-0.16759,-0.179386},{0.242174,-0.187279,-0.207139},{0.269159,-0.205326,-0.234436},{0.294662,-0.221915,-0.261319},{0.318796,-0.237204,-0.287825},{0.34166,-0.251331,-0.313987},{0.363347,-0.264415,-0.339835},{0.383942,-0.276561,-0.365395},{0.403521,-0.28786,-0.39069},{0.422155,-0.298393,-0.415741},{0.439907,-0.30823,-0.440567},{0.456838,-0.317434,-0.465185},{0.472999,-0.326062,-0.48961},{0.488442,-0.334162,-0.513856},{0.503212,-0.341779,-0.537935},{0.51735,-0.348953,-0.561859},{0.530896,-0.35572,-0.585639},{0.543884,-0.36211,-0.609283},{0.494357,-0.391212,-0.59409},{0.544532,-0.371891,-0.624278},{0.532423,-0.376033,-0.61613},{0.520022,-0.380612,-0.608372},{0.507332,-0.38566,-0.60102},{0.884377,-0.330631,-1.25289},{0.880486,-0.329395,-1.23548},{0.876499,-0.32817,-1.21817},{0.872415,-0.326957,-1.20096},{0.86823,-0.32576,-1.18386},{0.863942,-0.324579,-1.16686},{0.859547,-0.323417,-1.14998},{0.855042,-0.322276,-1.13321},{0.850424,-0.321159,-1.11657},{0.845688,-0.320069,-1.10004},{0.840833,-0.319008,-1.08364},{0.835853,-0.317979,-1.06737},{0.830745,-0.316987,-1.05124},{0.825506,-0.316033,-1.03524},{0.820132,-0.315123,-1.01939},{0.814618,-0.314261,-1.00369},{0.808961,-0.313451,-0.988136},{0.803156,-0.312697,-0.972743},{0.797199,-0.312005,-0.957514},{0.791085,-0.311381,-0.942452},{0.784812,-0.31083,-0.927565},{0.778373,-0.310359,-0.912858},{0.771765,-0.309974,-0.898337},{0.764984,-0.309683,-0.884008},{0.758024,-0.309493,-0.869878},{0.750882,-0.309414,-0.855953},{0.743553,-0.309453,-0.842241},{0.736033,-0.30962,-0.828748},{0.728318,-0.309925,-0.815483},{0.720403,-0.31038,-0.802452},{0.712286,-0.310996,-0.789664},{0.703962,-0.311785,-0.777127},{0.695429,-0.312761,-0.76485},{0.686683,-0.313937,-0.752841},{0.677722,-0.315328,-0.74111},{0.668544,-0.316951,-0.729665},{0.659148,-0.318821,-0.718518},{0.649533,-0.320958,-0.707676},{0.6397,-0.323379,-0.697151},{0.629648,-0.326104,-0.686953},{0.619382,-0.329155,-0.677093},{0.608902,-0.332554,-0.667581},{0.598216,-0.336323,-0.658428},{0.587328,-0.340487,-0.649646},{0.576246,-0.34507,-0.641246},{0.56498,-0.3501,-0.633239},{0.553542,-0.355603,-0.625636},{0.541946,-0.361607,-0.61845},{0.530209,-0.36814,-0.611691},{0.518349,-0.375233,-0.605371},{0.50639,-0.382913,-0.5995},{0.6454,-0.45127,-0.231232},{0.884377,-0.330631,-1.25289},{0.652228,-0.447823,-0.260422},{0.659055,-0.444376,-0.289612},{0.665883,-0.440929,-0.318803},{0.672711,-0.437482,-0.347993},{0.679539,-0.434036,-0.377183},{0.686367,-0.430589,-0.406373},{0.693195,-0.427142,-0.435564},{0.700023,-0.423695,-0.464754},{0.706851,-0.420248,-0.493944},{0.713679,-0.416801,-0.523134},{0.720507,-0.413355,-0.552324},{0.727335,-0.409908,-0.581515},{0.734163,-0.406461,-0.610705},{0.740991,-0.403014,-0.639895},{0.747818,-0.399567,-0.669085},{0.754646,-0.396121,-0.698276},{0.761474,-0.392674,-0.727466},{0.768302,-0.389227,-0.756656},{0.77513,-0.38578,-0.785846},{0.781958,-0.382333,-0.815037},{0.788786,-0.378886,-0.844227},{0.795614,-0.37544,-0.873417},{0.802442,-0.371993,-0.902607},{0.80927,-0.368546,-0.931797},{0.816098,-0.365099,-0.960988},{0.822926,-0.361652,-0.990178},{0.829754,-0.358206,-1.01937},{0.836582,-0.354759,-1.04856},{0.843409,-0.351312,-1.07775},{0.850237,-0.347865,-1.10694},{0.857065,-0.344418,-1.13613},{0.863893,-0.340971,-1.16532},{0.870721,-0.337525,-1.19451},{0.877549,-0.334078,-1.2237},{0.584616,-0.360402,-0.205652},{0.599812,-0.383119,-0.212047},{0.615008,-0.405836,-0.218442},{0.630204,-0.428553,-0.224837},{0.683379,0.397303,0.951894},{0.678416,0.389239,0.927541},{0.673385,0.380871,0.903028},{0.668286,0.372181,0.878346},{0.663124,0.363153,0.853489},{0.6579,0.35377,0.828447},{0.652619,0.344013,0.803212},{0.647283,0.333862,0.777775},{0.641899,0.323295,0.752126},{0.636472,0.312291,0.726254},{0.631009,0.300825,0.700148},{0.625518,0.288871,0.673796},{0.620009,0.276404,0.647187},{0.614493,0.263394,0.620305},{0.608982,0.249811,0.593138},{0.603491,0.235623,0.565669},{0.598038,0.220794,0.537883},{0.592642,0.205289,0.509762},{0.587325,0.18907,0.481288},{0.582113,0.172095,0.45244},{0.577037,0.154322,0.423198},{0.572129,0.135706,0.39354},{0.567429,0.116198,0.36344},{0.56298,0.0957503,0.332873},{0.558834,0.0743094,0.301812},{0.555048,0.0518219,0.270227},{0.551687,0.028232,0.238086},{0.548826,0.00348255,0.205357},{0.54655,-0.0224844,0.172003},{0.544954,-0.0497272,0.137985},{0.544148,-0.0783037,0.103263},{0.544255,-0.10827,0.0677936},{0.545413,-0.139678,0.0315303},{0.547779,-0.172577,-0.00557564},{0.551528,-0.207006,-0.0435761},{0.556856,-0.242995,-0.0825255},{0.563981,-0.280563,-0.122481},{0.573146,-0.319706,-0.163503},{-0.5,0.,0.}}

MeshCells[meshtest1, 2] is

{Polygon[{229,1,3}],Polygon[{229,3,4}],Polygon[{229,4,5}],Polygon[{229,5,6}],Polygon[{229,6,7}],Polygon[{229,7,8}],Polygon[{229,8,9}],Polygon[{229,9,10}],Polygon[{229,10,11}],Polygon[{229,11,12}],Polygon[{229,12,13}],Polygon[{229,13,14}],Polygon[{229,14,15}],Polygon[{229,15,16}],Polygon[{229,16,17}],Polygon[{229,17,18}],Polygon[{229,18,19}],Polygon[{229,19,20}],Polygon[{229,20,21}],Polygon[{229,21,22}],Polygon[{229,22,23}],Polygon[{229,23,24}],Polygon[{229,24,25}],Polygon[{229,25,26}],Polygon[{229,26,27}],Polygon[{229,27,28}],Polygon[{229,28,29}],Polygon[{229,29,30}],Polygon[{229,30,31}],Polygon[{229,31,32}],Polygon[{229,32,33}],Polygon[{229,33,34}],Polygon[{229,34,35}],Polygon[{229,35,2}],Polygon[{229,36,38}],Polygon[{229,38,39}],Polygon[{229,39,40}],Polygon[{229,40,41}],Polygon[{229,41,42}],Polygon[{229,42,43}],Polygon[{229,43,44}],Polygon[{229,44,45}],Polygon[{229,45,46}],Polygon[{229,46,47}],Polygon[{229,47,48}],Polygon[{229,48,49}],Polygon[{229,49,50}],Polygon[{229,50,51}],Polygon[{229,51,52}],Polygon[{229,52,53}],Polygon[{229,53,54}],Polygon[{229,54,55}],Polygon[{229,55,56}],Polygon[{229,56,57}],Polygon[{229,57,58}],Polygon[{229,58,59}],Polygon[{229,59,60}],Polygon[{229,60,61}],Polygon[{229,61,62}],Polygon[{229,62,63}],Polygon[{229,63,64}],Polygon[{229,64,65}],Polygon[{229,65,66}],Polygon[{229,66,67}],Polygon[{229,67,68}],Polygon[{229,68,69}],Polygon[{229,69,37}],Polygon[{229,70,72}],Polygon[{229,72,73}],Polygon[{229,73,74}],Polygon[{229,74,75}],Polygon[{229,75,76}],Polygon[{229,76,77}],Polygon[{229,77,78}],Polygon[{229,78,79}],Polygon[{229,79,80}],Polygon[{229,80,81}],Polygon[{229,81,82}],Polygon[{229,82,83}],Polygon[{229,83,84}],Polygon[{229,84,85}],Polygon[{229,85,86}],Polygon[{229,86,87}],Polygon[{229,87,88}],Polygon[{229,88,89}],Polygon[{229,89,90}],Polygon[{229,90,91}],Polygon[{229,91,92}],Polygon[{229,92,93}],Polygon[{229,93,94}],Polygon[{229,94,71}],Polygon[{229,71,96}],Polygon[{229,96,97}],Polygon[{229,97,98}],Polygon[{229,98,99}],Polygon[{229,99,95}],Polygon[{229,100,101}],Polygon[{229,101,102}],Polygon[{229,102,103}],Polygon[{229,103,104}],Polygon[{229,104,105}],Polygon[{229,105,106}],Polygon[{229,106,107}],Polygon[{229,107,108}],Polygon[{229,108,109}],Polygon[{229,109,110}],Polygon[{229,110,111}],Polygon[{229,111,112}],Polygon[{229,112,113}],Polygon[{229,113,114}],Polygon[{229,114,115}],Polygon[{229,115,116}],Polygon[{229,116,117}],Polygon[{229,117,118}],Polygon[{229,118,119}],Polygon[{229,119,120}],Polygon[{229,120,121}],Polygon[{229,121,122}],Polygon[{229,122,123}],Polygon[{229,123,124}],Polygon[{229,124,125}],Polygon[{229,125,126}],Polygon[{229,126,127}],Polygon[{229,127,128}],Polygon[{229,128,129}],Polygon[{229,129,130}],Polygon[{229,130,131}],Polygon[{229,131,132}],Polygon[{229,132,133}],Polygon[{229,133,134}],Polygon[{229,134,135}],Polygon[{229,135,136}],Polygon[{229,136,137}],Polygon[{229,137,138}],Polygon[{229,138,139}],Polygon[{229,139,140}],Polygon[{229,140,141}],Polygon[{229,141,142}],Polygon[{229,142,143}],Polygon[{229,143,144}],Polygon[{229,144,145}],Polygon[{229,145,146}],Polygon[{229,146,147}],Polygon[{229,147,148}],Polygon[{229,148,149}],Polygon[{229,149,150}],Polygon[{229,150,95}],Polygon[{229,151,153}],Polygon[{229,153,154}],Polygon[{229,154,155}],Polygon[{229,155,156}],Polygon[{229,156,157}],Polygon[{229,157,158}],Polygon[{229,158,159}],Polygon[{229,159,160}],Polygon[{229,160,161}],Polygon[{229,161,162}],Polygon[{229,162,163}],Polygon[{229,163,164}],Polygon[{229,164,165}],Polygon[{229,165,166}],Polygon[{229,166,167}],Polygon[{229,167,168}],Polygon[{229,168,169}],Polygon[{229,169,170}],Polygon[{229,170,171}],Polygon[{229,171,172}],Polygon[{229,172,173}],Polygon[{229,173,174}],Polygon[{229,174,175}],Polygon[{229,175,176}],Polygon[{229,176,177}],Polygon[{229,177,178}],Polygon[{229,178,179}],Polygon[{229,179,180}],Polygon[{229,180,181}],Polygon[{229,181,182}],Polygon[{229,182,183}],Polygon[{229,183,184}],Polygon[{229,184,185}],Polygon[{229,185,186}],Polygon[{229,186,152}],Polygon[{229,187,188}],Polygon[{229,188,189}],Polygon[{229,189,190}],Polygon[{229,190,151}],Polygon[{229,2,191}],Polygon[{229,191,192}],Polygon[{229,192,193}],Polygon[{229,193,194}],Polygon[{229,194,195}],Polygon[{229,195,196}],Polygon[{229,196,197}],Polygon[{229,197,198}],Polygon[{229,198,199}],Polygon[{229,199,200}],Polygon[{229,200,201}],Polygon[{229,201,202}],Polygon[{229,202,203}],Polygon[{229,203,204}],Polygon[{229,204,205}],Polygon[{229,205,206}],Polygon[{229,206,207}],Polygon[{229,207,208}],Polygon[{229,208,209}],Polygon[{229,209,210}],Polygon[{229,210,211}],Polygon[{229,211,212}],Polygon[{229,212,213}],Polygon[{229,213,214}],Polygon[{229,214,215}],Polygon[{229,215,216}],Polygon[{229,216,217}],Polygon[{229,217,218}],Polygon[{229,218,219}],Polygon[{229,219,220}],Polygon[{229,220,221}],Polygon[{229,221,222}],Polygon[{229,222,223}],Polygon[{229,223,224}],Polygon[{229,224,225}],Polygon[{229,225,226}],Polygon[{229,226,227}],Polygon[{229,227,228}],Polygon[{229,228,187}]}
$\endgroup$

1 Answer 1

1
$\begingroup$

Try with your definitions mp=MeshCoordinates[...] and me=MeshCells[...]

mesh=MeshRegion[mp,me]
flip = (FindMeshDefects[mesh, "FlippedFaces", "Cell"] // Normal)[[1,2]] 

flip is the list of all flipped triangles!

unflip the triangles:

meNew = me /. Map[({i1, i2, i3} = #[[1 ]]; # -> Polygon[{i1, i3, i2}]) & , flip]
meshNew=MeshRegion[mp,meNew]

enter image description here

Hope it helps!

$\endgroup$
2
  • $\begingroup$ It worked after modifying a little bit, as there are repetitions in my coordinate list. Thanks a lot! $\endgroup$
    – Qing Lan
    Commented Apr 13, 2023 at 16:41
  • $\begingroup$ You're welcome! $\endgroup$ Commented Apr 13, 2023 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.