How can I plot an intersection volume?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (2)
David Arnold
le 19 Juil 2018
Modifié(e) : David Arnold
le 30 Juil 2020
Here's a helpful starting image:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/192243/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/192245/image.png)
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.
0 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!