# How can I draw two intersecting spheres with highlighted intersection?

I would like to get an image like the this:

with two intersecting spheres, marked centers , one point on the intersection should also be marked and a highlighted intersection.

I've tried to get this work with pst-solides3d, but it took me some hours to get the example working (link) and it there it seems as if the intersection was marked manually. I could not get this cylinder/sphere intersection transformed to a sphere/sphere intersection. And the result looks not very nice.

• Would you consider the use of asymptote instead? asymptote.sourceforge.net – pluton Jun 30 '13 at 15:45
• @pluton: Yes. Everything that (i) produces vector graphics, (ii) is for free and (iii) is available for Linux is ok. – Martin Thoma Jun 30 '13 at 16:02
• you should have a look at asymptote.sourceforge.net/gallery/index.html and the impact.asy example that you could adapt. It takes some time to get used to asymptote but it is probably a relevant solution for such 3D figures. – pluton Jun 30 '13 at 16:14

\documentclass{minimal}
\usepackage{pst-solides3d}
\begin{document}

\psframebox{\begin{pspicture}(-4.5,-4)(5.5,2)
\psset{solidmemory,unit=0.55,
lightsrc=viewpoint,viewpoint=20 20 20 rtp2xyz,Decran=40}
\psSolid[object=sphere,r=2,ngrid=36 36,fillcolor=lightgray,
incolor=lightgray,hollow,name=sph1,action=none](3,0,0)
\psSolid[object=sphere,r=2,ngrid=36 36,fillcolor=lightgray,
incolor=lightgray,hollow,name=sph2,action=none](1,3,0)
\psSolid[object=fusion,base=sph1 sph2,opacity=0.5,action=draw**](0,0,0)
\end{pspicture}}

\end{document}


• Nice work :-) Is it possible to mark the intersection (a circle)? (By the way, I've added this to my repository as I don't know many pstricks examples and I know many others would like to have some examples, too) – Martin Thoma Jul 2 '13 at 13:51

This solution uses http://mathworld.wolfram.com/Sphere-SphereIntersection.html to get the coordinates of the intersection point P. spheres.tex:

\documentclass{article}
\usepackage{lmodern}
\usepackage[inline]{asymptote}
\begin{document}
\begin{figure}
\begin{asy}
settings.prc=false;
settings.render=0;
import graph3;

currentprojection=orthographic(camera=(150,900,412),up=(-0.4,-0.7,1.4),target=(100,111,1),zoom=0.5);
currentlight=nolight;
size(300);size3(300);

real r1=162;
real r2=100;

triple v1=(0,0,0);
triple v2=(250,0,0);

// from http://mathworld.wolfram.com/Sphere-SphereIntersection.html :
real d=arclength(v1--v2); // distance between v1,v2
real a=1/2/d*sqrt((2*d*r1)^2-(d^2-r2^2+r1^2)^2);

triple P=(sqrt(r1^2-a^2),0,-a);

triple fs1(pair t){
return v1+r1*(cos(t.x)*sin(t.y),sin(t.x)*sin(t.y),cos(t.y));
}

triple fs2(pair t){
return v2+r2*(cos(t.x)*sin(t.y),sin(t.x)*sin(t.y),cos(t.y));
}

surface s1=surface(fs1,(0,0),(2pi,pi),16,Spline);
surface s2=surface(fs2,(0,0),(2pi,pi),16,Spline);

draw(s1
,darkgreen+opacity(0.2)
,render(compression=Low,merge=true)
);

draw(s2
,darkblue+opacity(0.2)
,render(compression=Low,merge=true)
);

dot(v1); label("$V_1$",v1,-X+Z);
dot(v2); label("$V_2$",v2,-X+Z);
dot(P); label("$P$",P,-X-Z);
\end{asy}
\end{figure}
\end{document}


To process it with latexmk, create file latexmkrc:

sub asy {return system("asy '\$_[0]'");}

and run latexmk -pdf spheres.tex.