1
$\begingroup$

I am trying to compute the volume of a 3-dimensional region defined by 5 inequalities. Mathematica takes too long to compute it. In fact, I haven't ever seen it complete the execution of the below code:

theta = Pi/5;
dh = 0.5;
din = 1.016;
dout = 1.27;
zz = z * Cos[theta] - x*Sin[theta];
xx = z * Sin[theta] + x*Cos[theta];
yy = y;
region1 = 
z^2 >= (dh/2 + 0.0254)^2 - (dout/2)^2*
x^2/(x^2 + y^2);
region2 = (din/2)^2 < 
x^2 + y^2 < (dout/2)^2;
region3 = -1 <= z <= 1;
region4 = zz^2 <= (dh/2)^2 - (dout/2)^2*
xx^2/(xx^2 + yy^2);
region5 = (din/2)^2 < xx^2 + yy^2 < (dout/2)^2; 
region = ImplicitRegion[{region1, region2, region3, region4, region5}, {x, y, z}];
Volume[region]

Any reason why it takes so long (or does not complete)? Any alternative method to compute the volume (that does not involve discretization)?

EDIT: Calculating the volume of even two of the regions similarly takes too long:

theta = Pi/5;
dh = 0.5;
din = 1.016;
dout = 1.27;
zz = z * Cos[theta] - x*Sin[theta];
xx = z * Sin[theta] + x*Cos[theta];
yy = y;
regionA = zz^2 <= (dh/2)^2 - (dout/2)^2 * xx^2/(xx^2 + yy^2);
regionB = (din/2)^2 < xx^2 + yy^2 < (dout/2)^2; 
region = ImplicitRegion[{regionA, regionB}, {x, y, z}];
Volume[region]
$\endgroup$
  • 1
    $\begingroup$ I do not recommend the use of either D[] (the differentiation operator) nor subscripts in your code; consider eliminating them. $\endgroup$ – J. M. will be back soon Jul 13 '16 at 16:20
  • $\begingroup$ @J.M. Edited. Thanks $\endgroup$ – Shivanand Jul 13 '16 at 16:24
  • $\begingroup$ @Feyre But Mathematica must at least show that the volume is zero. I want to compute this for different values of theta, dh, din and dout and not all of them necessarily give zero volume $\endgroup$ – Shivanand Jul 13 '16 at 16:28
  • $\begingroup$ Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Jul 13 '16 at 16:33
  • $\begingroup$ For some reason, it won't discretize the region if region1 is included, but: r2 = DiscretizeRegion[region, {{-1, 1}, {-1, 1}, {-1, 1}}] Volume[r2] 0.033056 $\endgroup$ – Feyre Jul 13 '16 at 16:42
2
$\begingroup$

You should discretize your region, taking care to avoid singularities, here I leave out region 1:

region = ImplicitRegion[{region2, region3, region4, region5}, {x, y, 
z}];
r2 = DiscretizeRegion[region, {{-1, 1}, {-1, 1}, {-1, 1}}]

enter image description here

Now you can calculate the volume:

AbsoluteTiming[Volume[r2]]

{0.000382, 0.0330559}

$\endgroup$
  • $\begingroup$ I need to add region1 too. Do you know why it cannot be discretized the way other regions can be? $\endgroup$ – Shivanand Jul 13 '16 at 19:10
  • $\begingroup$ @Shivanand All I know is that when region1 and 4 come together, i get an error which is unknown to google. TriangulateMesh::tmfail: TriangulateMesh failed to triangulate the mesh. >> $\endgroup$ – Feyre Jul 13 '16 at 20:39
  • $\begingroup$ I know for sure that the intersection is very small. Each region is very important for the final result $\endgroup$ – Shivanand Jul 13 '16 at 21:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.