0
$\begingroup$

A MeshRegion seems to function quite differently from any other Mathematica expression. One cannot take a Part of it. Nor can I simply exchange its head to something else using Apply. What is going on here and how do I extract the argument in some manipulable form?

$\endgroup$
  • 1
    $\begingroup$ MeshRegion is an atomic expression. See also AtomQ $\endgroup$ – Pinti Jan 27 at 13:22
  • $\begingroup$ @Pinti, thanks! That is really annoying though and there does not seem to be a good reason why it would need to be. If you look at the FullForm you see that it would be perfectly possible to select its arguments. $\endgroup$ – Kvothe Jan 27 at 13:31
  • 2
    $\begingroup$ That's what you use MeshCoordinates[] and MeshCells[] for. $\endgroup$ – J. M.'s technical difficulties Jan 27 at 13:35
  • $\begingroup$ As for why MeshRegion is like this it is probably for similar reasons as for Graph which are discussed here mathematica.stackexchange.com/questions/127522/…. $\endgroup$ – Kvothe Jan 27 at 13:44
1
$\begingroup$

MeshRegion is an atomic expression. This may be to allow an optimized internal form. See an explanation for why Graph is atomic in Why is Graph an atomic expression in Mathematica?. Parts can be taken using MeshCoordinates[], MeshCells[] and Options[]. (I do not know whether these three functions can obtain all data contained in a MeshRegion but for now it seems like it.)

Another workaround would be to convert to a String and act on that:

takeArgumentMeshRegion[meshreg_]:=ToExpression@StringCases[ToString[FullForm@meshreg],"MeshRegion["~~x__~~"]":>"{"<>x<>"}"];

However, this might be a bad idea since there is a reason why Mathematica tries to keep us from taking arguments like this.

| improve this answer | |
$\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.