I started this mainly for fun, I guess, but it makes a nice, sharp plot. The region needs to have a nice CylindricalDecomposition
.
Reduce
will compute this, too. It makes a predictable format that can be rewritten easily into code for other standard Mathematica functions.
CylindricalDecomposition[z < 1 - x^2 - y^2 && z >= 0 && z > 1 - y, {y, x, z}]
Reduce[z < 1 - x^2 - y^2 && z >= 0 && z > 1 - y, {y, x, z}]
Reduce[z < 1 - x^2 - y^2 && z >= 0 && z > 1 - y, z]
(* all give the same answer:
0 < y < 1 && -Sqrt[y - y^2] < x < Sqrt[y - y^2] && 1 - y < z < 1 - x^2 - y^2
*)
This example gives a simple cylindrical decomposition. Often a region can be written only as a sum of such cylindrical regions. CylindricalDecomposition
returns the "sum" in the form
Or[cd1, cd2,...]
This case, too, is easy to handle (e.g. replace Or
by List
, perhaps), but how to do it depends on the application. So I will leave it to the interested reader to explore.
Code:
ClearAll[cdapply];
cdapply[f_, argsfn_: List, opts___] :=
HoldPattern[
And[_[u1_, ___, u_Symbol /; Context[u] === "Global`", ___, u2_],
_[v1_, ___, v_Symbol /; Context[v] === "Global`", ___, v2_], _[w1_, ___, w2_]]
] :> f[argsfn[w1, w2], {u, u1, u2}, {v, v1, v2}, opts];
The need for ___
between the arguments is because there are two ways to express an inequality $a < b < c$:
Less[a, b, c]
Inequality[a, Less, b, Less, c]
The pattern matches both, but the code does assume the inequality is Less
(or LessEqual
).
OP's example, with three views of the result:
cd = Reduce[z < 1 - x^2 - y^2 && z >= 0 && z > 1 - y, z];
cd /. cdapply[Plot3D, List, PlotPoints -> 50];
GraphicsRow[{%, %, %}]

cd /. cdapply[Integrate, #2 - #1 &]
(* π/32 *)
Here's what code the replacement rule is constructing:
cad /. cdapply[Inactive@Plot3D, List, PlotPoints -> 50]

cad /. cdapply[Inactive[Integrate], #2 - #1 &]

One could adapt the replacement rule to handle functions like Integrate
that allow three or more parameters as arguments.
ClearAll[cdapplyAll];
cdapplyAll[f_, argsfn_: (1 &), opts___] :=
HoldPattern[
And[_[u1_, ___, u_Symbol /; Context[u] === "Global`", ___, u2_],
_[v1_, ___, v_Symbol /; Context[v] === "Global`", ___, v2_],
_[w1_, ___, w_Symbol /; Context[w] === "Global`", ___, w2_]]
] :> f[argsfn[{u, u1, u2}, {v, v1, v2}, {w, w1, w2}],
{u, u1, u2}, {v, v1, v2}, {w, w1, w2}, opts];
cd /. cdapplyAll[Integrate]
(* π/32 *)
cad /. cdapplyAll[Inactive[Integrate]]

ImplicitRegion
andVolume
? $\endgroup$