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

35 views (last 30 days)
Samira on 16 Apr 2013
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 on 16 Apr 2013
Edited: Kye Taylor on 16 Apr 2013
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.
Jelle on 26 Apr 2013
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])