3
$\begingroup$

I am using MeshPrimitives to get a list of 3D components of a Mesh Region. Within that list, I normally get some incorrectly specified regions, such as

Tetrahedron[{{1.9, 0.45, 2.}, {1.8, 0.3, 2.}, {1.8, 0.6, 2.}, {1.6, 0.5, 2.}}]

This is, of course, incorrectly specified because all the points are are in the same Z-plane and thus a function like RegionCentroid will fail. I would like to find a way to use DeleteCases or something similar to remove all the incorrectly specified regions in my list, but I don't know how make a pattern for it. Any suggestions? Is there a way to remove items that throw an error when a certain function is applied?

$\endgroup$
  • 3
    $\begingroup$ Select[list, RegionQ]? $\endgroup$ – ilian Jul 8 '15 at 15:04
  • $\begingroup$ That's what I was looking for. I didn't know RegionQ existed. Thanks! $\endgroup$ – BenP1192 Jul 8 '15 at 15:07
  • 1
    $\begingroup$ Ben, if that solves your problem, would you consider posting an expanded version of @ilian's comment as an answer to your question, maybe with an example of data and usage too? Answering your own question is encouraged here on stackexchange, and having a complete answer makes a question that much more valuable to future users with a similar problem. $\endgroup$ – MarcoB Jul 8 '15 at 15:12
2
$\begingroup$

The best solution is to use RegionQ, a simple solution suggested by ilian. RegionQ is a function that takes a region as an argument and returns whether it is a valid region. Here is how I used it:

regCells = Select[MeshPrimitives[DiscretizedRegion, 3], RegionQ];

This only keeps the regions returned by MeshPrimitives which are valid regions, which allows region-based functions to be applied to the list regCells without throwing errors.

$\endgroup$

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.