I load a custom region, specified as BoundaryMeshRegion

R = Import["C:\\data\\Profile.stl", "BoundaryMeshRegion"]

region import

and I try to find an intersection

intersection = RegionIntersection[R, InfiniteLine[RegionCentroid[R], {1, 0, 0}]]


region bounds

And I get errors:

intersection errors

Is this supposed to work ? I can't figure out what I am doing wrong, here's all the troubleshooting I could think of:

region troubleshooting

I would really appreciate any tips on what I am doing wrong, this functionality works with standard regions like Ball[], I would really like this to work on my region too!

  • 2
    $\begingroup$ Please try to upload Profile.stl somewhere; your question is unanswerable otherwise. $\endgroup$ – J. M.'s torpor Oct 12 '18 at 15:05
  • $\begingroup$ File added ufile.io/jo8j6 ! $\endgroup$ – Anatoly Oct 12 '18 at 19:12
  • 2
    $\begingroup$ It seems like there's no intersection: Show[{R, DiscretizeRegion[InfiniteLine[RegionCentroid[R], {0, 0, 1}], RegionBounds[R]]}] $\endgroup$ – halmir Oct 15 '18 at 13:07
  • $\begingroup$ Thank you @halmir for pointing that out! I changed line direction to {1,0,0} to make sure they do cross, still same error though :( Line direction {0,1,0} produces the same error again $\endgroup$ – Anatoly Oct 15 '18 at 19:39

As a workaround, you could take boundary polygons and find intersection:

poly = Polygon[MeshPrimitives[R, 2][[All, 1]]];

line = InfiniteLine[RegionCentroid[R], {1, 0, 0}];

intersection = 
   InfiniteLine[RegionCentroid[R], {1, 0, 0}]];

RegionMeasure[Line @@ intersection]


or to reduce computation time:

polys = MeshPrimitives[R, 2];

ipolys = Pick[polys, RegionDisjoint[line, #] & /@ polys, False];

intersection = RegionIntersection[line, Polygon@ipolys[[All, 1]]]
  • $\begingroup$ Thank you @halmir, this works! I can use it as a workaround for now, after I figure out what it does :) $\endgroup$ – Anatoly Oct 17 '18 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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