I want to show intersection of these two spheres. How should I do it?
조회 수: 9 (최근 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)
댓글 수: 0
채택된 답변
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
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
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 Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!