I want to show intersection of these two spheres. How should I do it?

19 次查看(过去 30 天)
theta=linspace(0,2*pi,40);
phi=linspace(0,pi,40);
[theta,phi]=meshgrid(theta,phi);
r=1;
x=r*sin(phi).*cos(theta);
y=r*sin(phi).*sin(theta);
z=r*cos(phi);
mesh(x,y,z)
hold on
theta=linspace(0,2*pi,40);
phi=linspace(0,pi,40);
[theta,phi]=meshgrid(theta,phi);
r=1;
x=r*sin(phi).*cos(theta);
y=r*sin(phi).*sin(theta);
z=r*cos(phi);
x=x+0.25;
y=y-0.2;
z=z+0.1;
surf(x,y,z)

采纳的回答

Kye Taylor
Kye Taylor 2013-4-16
编辑:Kye Taylor 2013-4-16
The spheres you describe have equations
1.) x^2 + y^2 + z^2 = 1
2.) (x-0.25)^2 + (y+1/5)^2 + (z-0.1)^2 = 1
Since equations 1 and 2 have same right-hand-side (equal to one), set the left-hand sides equal and you'll end up getting rid of the squared terms to be left with
3.) 5*x+4*y+2*z = 9/8
Equation 3 is the equation for the plane that contains the intersection of the two spheres. To see it add these lines of code to the end of your code above.
[X,Y] = meshgrid(linspace(-1,1,20));
Z = -5/2*X + 2*Y + 9/16;
surf(X,Y,Z)
That gives you the plane that contains the intersection. Realize that the intersection of the spheres is actually a curve that is a circle in this plane. Parametrizing that circle is more complicated.
  3 个评论
Kye Taylor
Kye Taylor 2013-4-16
My pleasure!
What do you mean by common value? As you move along the curve where the two spheres meet, the values of (x,y,z) will change.
Jelle
Jelle 2013-4-26
In case you guys haven't seen it yet, there is a sign mistake in the code. Equation 3 is correct and hence the code should be:
[X,Y] = meshgrid(linspace(-1,1,20));
Z = -5/2*X + 2*Y - 9/16;
surf(X,Y,Z)
This answer is validated by plotting both unit spheres and the plane that contains the intersection.
[X,Y] = meshgrid(linspace(-1,1,20));
Z = -5/2*X + 2*Y - 9/16;
surf(X,Y,Z)
hold on
[x,y,z] = sphere;
surf(x,y,z)
surf((x-0.25),(y+0.2),(z-0.1))
daspect([1 1 1])

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by