2
$\begingroup$

From this question I'm using a function by kglr to find the inequality constraints for a shape.

The function is this

constraints[shapes__] := 
 And[## & @@ (Not /@ 
      Through[(RegionMember[RegionIntersection@##] & @@@ 
          Subsets[{shapes}, {2}])@#]), 
   RegionMember[RegionUnion @@ (RegionBoundary /@ {shapes})]@#] &

This works great if I have a shape with just integers. The inequalities is exactly what I would expect

constraints[Cuboid[{1, 1, 1}, {2, 2, 2}]][{x, y, z}]

Returns

(x | y | z) \[Element] Reals && ((-1 + z == 0 && -1 + y >= 0 && 3 - x - y >= 0 &&  2 - x <= 1) || (-1 + z == 0 &&   2 - y >= 0 && -3 + x + y >= 0 && -1 + x <= 1) || (-1 + x == 0 && -1 + y >= 0 && -y + z >= 0 && -1 + z <= 1) || (-1 + x == 0 && 2 - y >= 0 && y - z >= 0 && 2 - z <= 1) || (-2 + y == 0 && -1 + x >= 0 && -x + z >=  && -1 + z <= 1) || (-2 + y == 0 && 2 - x >= 0 && x - z >= 0 &&  2 - z <= 1) || (-2 + x == 0 && 2 - y >= 0 && -3 + y + z >= 0 && -1 + z <= 1) || (-2 + x == 0 && -1 + y >= 0 && 3 - y - z >= 0 &&  2 - z <= 1) || (-1 + y == 0 &&  2 - x >= 0 && -3 + x + z >= 0 && -1 + z <= 1) || (-1 + y == 0 && -1 + x >= 0 && 3 - x - z >= 0 &&   2 - z <= 1) || (-2 + z == 0 && -1 + y >= 0 && x - y >= 0 && -1 + x <= 1) || (-2 + z == 0 && 2 - y >= 0 && -x + y >= 0 && 2 - x <= 1))

Which is great. However, if within the shape definition there a non-integer value, the function will not return an analytical result, i.e.

 constraints[Cuboid[{1, 1, 1}, {2, 2, 1.5}]][{x, y, z}]

will not work. Note, that the second vector in Cuboid has a 1.5. I cannot find out what section of the function is causing the problem & how I might solve it. At the moment I manually go through and amend the inequalities - this is not ideal.

$\endgroup$
  • 2
    $\begingroup$ As a workaround, you may use rational numbers: constraints[Cuboid[{1, 1, 1}, {2, 2, 3/2}]][{x, y, z}] works fine. Apparently, RegionMember assumes that there is no reasonable chance to return a analytic function if there are floating point number present (which is, well, wrong). But it is actually very desirable that RegionMember is overly conservative: This way it does not waste precious time building the function in case of too complicated expression. $\endgroup$ – Henrik Schumacher Feb 25 '18 at 20:42
2
$\begingroup$

What happens is that with approximate numbers (e.g. 1.5), approximate methods are invoked, namely in this case, the region is discretized:

First@Head@constraints[Cuboid[{1, 1, 1}, {2, 2, 1.5}]][{x, y, z}]

Mathematica graphics

% // InputForm
(*
MeshRegion[
 {{2., 1., 1.}, {2., 2., 1.}, {1., 2., 1.}, {1., 1., 1.}, {1., 2., 1.5},
  {1., 1., 1.5}, {2., 2., 1.5}, {2., 1., 1.5}},
 {Polygon[{{1, 3, 4}, {4, 5, 6}, {3, 7, 5}, {2, 8, 7}, {1, 6, 8}, {6, 7, 8},
   {3, 1, 2}, {5, 4, 3}, {7, 3, 2}, {8, 2, 1}, {6, 1, 4}, {7, 6, 5}}]}]
*)

Numerical methods are used to compute the RegionMemberFunction for a MeshRegion, so a symbolic formula is not produced.

With exact input, as Henrik suggested, exact methods are used and if feasible, an exact symbolic description of the region will be produced.

$\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.