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

16 ビュー (過去 30 日間)
Samira
Samira 2013 年 4 月 16 日
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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by