How can I plot an intersection volume?

8 views (last 30 days)
Johannes
Johannes on 19 Nov 2012
Edited: David Arnold on 30 Jul 2020
Hey,
I am trying to plot a sphere V that is intersecting with a cylinder Z.
Z = (x;y;z) x^2+y^2=1 ; 0<z<5
V = (x;y;z) x^2+y^2+z^2=4
I just want to plot the volume of intersection.
How do I do that?
Thanks for your help

Answers (2)

Sean de Wolski
Sean de Wolski on 19 Nov 2012

David Arnold
David Arnold on 19 Jul 2018
Edited: David Arnold on 30 Jul 2020
Here's a helpful starting image:
We can see that tan(phi)=1/sqrt(3), so phi=pi/6. Now, here's my code to draw the region using the Symbolic Toolbox. I use cylindrical coordinates to draw the cylinder and spherical coordinates to draw the sphere, the top piece goes from 0<phi<pi/6 and the bottom piece from 5pi/6<phi<pi.
syms r t z
r=1;
x=r*cos(t);
y=r*sin(t);
fsurf(x,y,z,[0,2*pi,-sqrt(3),sqrt(3)])
hold on
syms rho phi theta
rho=2;
x=rho*sin(phi)*sin(theta);
y=rho*sin(phi)*cos(theta);
z=rho*cos(phi);
fsurf(x,y,z,[0,pi/6,0,2*pi])
fsurf(x,y,z,[5*pi/6,pi,0,2*pi])
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
view(120,5)
rotate3d on
This code produces this image:
And here is a numerical approach.
n=20;
t=linspace(0,2*pi,20);
z=linspace(-sqrt(3),sqrt(3),20);
[T,Z]=meshgrid(t,z);
X=cos(T);
Y=sin(T);
surf(X,Y,Z)
hold on
theta=linspace(0,2*pi,20);
phi=linspace(0,pi/6,20);
[THETA,PHI]=meshgrid(theta,phi);
rho=2;
X=rho*sin(PHI).*cos(THETA);
Y=rho*sin(PHI).*sin(THETA);
Z=rho*cos(PHI);
surf(X,Y,Z)
phi=linspace(5*pi/6,pi,20);
[THETA,PHI]=meshgrid(theta,phi);
rho=2;
X=rho*sin(PHI).*cos(THETA);
Y=rho*sin(PHI).*sin(THETA);
Z=rho*cos(PHI);
surf(X,Y,Z)
grid on
axis([-3,3,-3,3])
text(-0.7,1,'sqrt(3)')
text(0.6,0.8,'2')
text(0.35,1.9,'1')
text(.1,.5,"\phi")
axis equal
view(120,5)
rotate3d on
It will give a similar image.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!