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.
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 thatRegionMember
is overly conservative: This way it does not waste precious time building the function in case of too complicated expression. $\endgroup$