How can I find a common volume of three cones intersecting each other in MATLAB?

1k views Asked by At

I have plotted three cones which are intersecting each other at certain height. I need to find out the common volume of the intersection but I can't figure that out! Is there any built-in function in MATLAB, which can calculate the volume of interest? I would also like to highlight that region with stronger color. Any advice?

The plotted picture can be seen below:

enter image description here

Regards, TK

1

There are 1 answers

0
AudioBubble On

I'll illustrate the principle with a similar triple intersection, replacing two of the cones by cylinders. (Also, I'm not answering about coloring. One question per question, please.)

Suppose I want the volume within 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 the solid from below only. The cylinders can do it from the top and from the bottom: solving their equations for z gives two values, top and bottom.

The vertical size of the solid over a point (x,y) can be found as

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

Specifically:

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)

Which outputs 5.3333.

Note that sqrt(max(0,...)) is used to prevent Matlab from getting complex numbers, should the content of square root be negative. This is useful because the limits of integration (-1,1,-1,1 above) generally correspond to some bounding rectangle for the projection onto xy-plane, so within this rectangle some of the formulas might not be really defined. For example, you could use

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

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