How can I find the total volume of three cones intersecting each other in MATLAB?

I have built three cones that intersect with each other at a certain height. I need to figure out the total amount of intersection but I can't figure it out! Is there a built-in function in MATLAB that can calculate the volume of interest? I would also like to highlight this region with a stronger color. Any advice?

The pictured picture can be seen below:

enter image description here

Regards, TK

+3


source to share


1 answer


I will illustrate the principle with a similar triple intersection by replacing the two cones with cylinders. (Also, I am not answering the coloring book. One question per question, please.)

Suppose I want volume inside the cone z = x ^ 2 + y ^ 2, cylinder x ^ 2 + (z-2) ^ 2 = 1 and cylinder y ^ 2 + (z-2) ^ 2 = 1. The cone bounds solid underneath. Cylinders can do this from above and from below: solving their equations for z gives two values: top and bottom.

The vertical dimension of the solid above the point (x, y) can be found as

max(0, min(all tops) - max(all bottoms))

      

In particular:



vcone = @(x,y) sqrt(x.^2+y.^2);          % cone, bottom only 
c1top = @(x,y) 2+sqrt(max(0,1-x.^2));    % 1st cylinder, top part
c1bot = @(x,y) 2-sqrt(max(0,1-x.^2));    % 1st cylinder, bottom part
c2top = @(x,y) 2+sqrt(max(0,1-y.^2));    % 2nd cylinder, top part
c2bot = @(x,y) 2-sqrt(max(0,1-y.^2));    % 2nd cylinder, bottom part

height = @(x,y) max(0, min(c1top(x,y),c2top(x,y)) - max(vcone(x,y),max(c1bot(x,y),c2bot(x,y))));  

integral2(height, -1, 1, -1, 1)

      

What are the outputs 5.3333.

Note that this is sqrt(max(0,...))

used to prevent Matlab from getting complex numbers if the content of the square root is negative. This is useful because the limits of integration (-1.1, -1.1 above) usually correspond to some bounding rectangle for projection onto the xy plane, so some formulas may not be defined inside this rectangle. For example, you can use

integral2(height, -2, 2, -2, 2)

      

to get the same result, although the equations of the cylinders break down when | x | or | y | exceed 1.

0


source







All Articles