9

I've made the following code:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usepackage[english]{babel}
\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}

\shade[ball color=red] (0,0,0) circle (2cm);
\fill[opacity=0.5,blue] (-3,0,1) -- (-1,2,1) -- (5,2,1) -- (3,0,1) -- cycle;

\end{tikzpicture}


\end{document}

Which I've adapted from this post (thank you very much!). And which produces:

enter image description here

But I want to do is this:

enter image description here

Question: How could I do the intersection of the sphere with the plane?

  • Does it need to be "true" 3D? Or is it sufficient to look like it? The former is more difficult (especially with TikZ), the latter is way less flexible. – Tom Bombadil Dec 5 '15 at 2:32
  • It doesn't need to be true 3D. I just want it to look like if it was. ;) – francolino Dec 5 '15 at 2:34
  • it helps if the ellipse has the same aspect ration (width to height) at the parallelogram. – John Kormylo Dec 5 '15 at 4:13
13

Here's a solution with Asymptote:

plane and sphere

The code to produce it:

\documentclass{standalone}
\usepackage{asypictureB}

\begin{document}

\begin{asypicture}{name=SphereAndPlane}
settings.outformat = "png";
settings.render = 8;
size(10cm, 0);  // Final image will be 10cm wide, unlimited height.
import three;   // Enable three-dimensional functionality.
currentprojection = orthographic(2,5,1);

draw(unitsphere, red);
draw(surface((-2,-2,0) -- (-2,2,0) -- (2,2,0) -- (2,-2,0) -- cycle), blue + opacity(0.5));

\end{asypicture}

\end{document}

% file: foo.tex
% to compile: pdflatex --shell-escape foo
%
% For MikTeX users: Asymptote requires a separate program that cannot be installed
% by the package manager. You can get the installation file from
% https://sourceforge.net/projects/asymptote/files/2.35/
% (specifically, the file ending in setup.exe).

If you are using a relatively recent version of MacTeX (or, I assume, TeX Live), with a full installation, this should just work. If you are using MikTeX, you will need to install the Asymptote program as described in the comments after \end{document}.

  • Nice! Sorry I forgot to mention Asymptote. Probably one day I'll have a look at it. – Tom Bombadil Dec 5 '15 at 9:21
  • +1 for asypictureB – alfC Dec 5 '15 at 9:43
11

Here you have an idea for both: the "fake" 3D draws two planes, one "behind" the ball, and one "in front of". The 3D effect is achieved by cutting out a half ellipse. The "less fake" 3D approach uses pgfplots to first draw the lower hemisphere, then the surface, and then the upper hemisphere. Probably someone will upload a pstricks solution, as it is vastly superior at 3D stuff.

Code

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}
    \fill[blue!50!gray, opacity=0.7] (0,0) -- (5,0) -- (4,2) -- (1,2) -- cycle;
    \shade[ball color=red] (2.5,0) circle (1);
    \fill[blue!50!gray, opacity=0.7] (0,0) -- (1.5,0) arc (180:360:1 and 0.5) -- (5,0) -- (6,-2) -- (-1,-2) -- cycle;
\end{tikzpicture}

\begin{tikzpicture}
    \begin{axis}
    [   axis equal,
        hide axis,
        view={30}{30},
        z buffer=sort,
    ]
        \addplot3
        [   domain=0:360,
            y domain=0:180,
            surf,
            shader=flat,
            red,
            opacity=0.5
        ] ({sin(y)*cos(x)},{sin(y)*sin(x)},{cos(y)});
        \addplot3
        [   domain=-2:2,
            y domain=-2:2,
            surf,
            shader=flat,
            blue,
            opacity=0.5,
        ] (x,y,0);
        \addplot3
        [   domain=0:360,
            y domain=0:90,
            surf,
            shader=flat,
            red,
            opacity=0.5,
        ] ({sin(y)*cos(x)},{sin(y)*sin(x)},{cos(y)});
    \end{axis}
\end{tikzpicture}

\end{document}

Output

enter image description here

8

Run with xelatex

\documentclass[pstricks]{standalone}
\usepackage{pst-solides3d}

\begin{document}
\psset{viewpoint=50 0 10 rtp2xyz,Decran=70,lightsrc=80 20 70,
       linewidth=0.001pt,action=none}
\begin{pspicture}[solidmemory](-4,-2)(4,2)
%\axesIIID(3,3,6)
\psSolid[object=plan,definition=equation,args={[0 0 1 0]},
base=-3 3 -2 2,ngrid=20 20,fillcolor=red!30,name=B1]
\psSolid[object=sphere,r=1,fillcolor=cyan,ngrid=18 36,
name=C1,action=none]
\psSolid[object=fusion,base=B1_s C1,action=draw**]
\end{pspicture}

\end{document}

enter image description here

  • I knew I could count on you to provide a pstricks solution :-) – Tom Bombadil Dec 5 '15 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.