Mathematica 13.1 on Windows 10.
Can someone explain why the following does not match:
MatchQ[BoundaryMeshRegion[Cube[]], BoundaryMeshRegion[__]]
(* False *)
Mathematica 13.1 on Windows 10.
Can someone explain why the following does not match:
MatchQ[BoundaryMeshRegion[Cube[]], BoundaryMeshRegion[__]]
(* False *)
As was pointed out in the comments, the reason of the no-match is, that BoundaryMeshRegion is atomic.
My ultimate goal is to change the innards of a BoundaryMeshRegion or any other atomic object. Toward this aim, the function Nucleus from Carl Woll is a big step forward.
I give here a simple example how to change a BoundaryMeshRegion of a Rectangle:
First the function Nucleus from Carl Woll:
Nucleus[input_, head_ : Automatic] :=
With[{atoms =
Replace[head, {Automatic :>
If[AtomQ[input], {Head[input]},
Message[Nucleus::atom]; $Failed], h_Symbol :> {h},
h : {__Symbol} :>
h, _ :> (Message[Nucleus::syms, head, 2]; $Failed)}]}, (If[!
MemberQ[Links[], $AtomLink] || LinkReadyQ[$AtomLink],
Quiet@LinkClose[$AtomLink];
$AtomLink = LinkCreate[LinkMode -> Loopback]];
LinkWrite[$AtomLink, input];
inactiveBlock[atoms, LinkRead[$AtomLink]]) /; atoms =!= $Failed]
SetAttributes[inactiveBlock, HoldAll]
inactiveBlock[h_List, body_] :=
Block @@
Join[Apply[Set, Hold@Evaluate@Thread[{h, Inactive /@ h}], {2}],
Hold[body]]
Nucleus::syms =
"Argument 1 at position 2 is expected to be a symbol or a list
of symbols";
Nucleus::atom = "Unable to determine atomic symbol";
The BoundaryMeshRegion of some rectangle is:
bmr=BoundaryMeshRegion[Rectangle[{0, 0}]]
and the FullForm of the atom:
nuc= Nucleus[bmr];
FullForm[nuc]
We may now change the coordinate of the first vertex. Note that the real number are written with a tick:
changed= nuc /. {0.`, 0.`} -> {0.5, 0};
Finally we may re-activate the changed rectangle:
Activate[changed]
_BoundaryMeshRegionas a pattern it will work. – Jason B. Sep 08 '22 at 13:28MatchQ[Unevaluated@BoundaryMeshRegion[Cube[]], BoundaryMeshRegion[___]]givesTrue– Nasser Sep 08 '22 at 13:32MeshCoordinates,MeshCells,MeshPrimitives. There are hacky methods to get at theInputFormbut they are rarely the right way to do things. – Jason B. Sep 08 '22 at 13:36Unevaluatedis needed inMathQ. Here is an example