0

I want to draw a sphere whose latitude is the circle of the base of a cone. enter image description here

This is my code

\begin{tikzpicture}[scale=1, font=\footnotesize, line join=round, line cap=round, >=stealth]
\def\a{1}

\def\b{0.4}

\def\h{3}

\pgfmathsetmacro\g{asin(-\b/\h)}

\pgfmathsetmacro\xo{\a *cos(\g)}

\pgfmathsetmacro\yo{\b *sin(\g)}

\draw[dashed] (\xo,\yo) arc (\g:180-\g:{\a} and {\b});

\draw (\xo,\yo) arc (\g:-180-\g:{\a} and {\b}) -- (-90:\h) --cycle;

\begin{scope}

\draw[dashed] (\xo,\yo) arc (\g:-180-\g:{\a});

\draw (\xo,\yo) arc (\g:180-\g:{\a});

\end{scope}

\end{tikzpicture}

SebGlav
  • 19,186
  • You will need to do some math if you want to draw this manually in 2D. Here the sphere and the cone base share the same diameter, hence the sphere intersects the cone. You have to define the diameter of the cone base and the diameter of the shpere, in the first place. Take a look at this question and its answers, which may give you hints on how to start. – SebGlav Jul 24 '21 at 09:38

2 Answers2

4

Here's a starting point with the basic computing:

sphere inside a cone

\begin{document}
\begin{tikzpicture}
    \def\R{5}   % R is the radius of the sphere
    \def\r{4.8} % r is the radius of the cone base
    \pgfmathsetmacro\h{sqrt(\R*\R-\r*\r)} 
    \pgfmathsetmacro\a{asin(\r/\R)}
    \pgfmathsetmacro\H{\r*tan(\a)}

    %\draw[red,thick] (0,0) -- (-90+\a:\R);

    \path   (-\r,-\h) coordinate (S) --++ (\r,0) coordinate (K) --++ (\r,0) coordinate (T)
            (0,0) coordinate (O) --++ (0,-\h-\H) coordinate (U);

    % Wireframe
    \draw   (T) arc (-90+\a:270-\a:\R);
    \draw   (S) -- (U) -- (T)
            (T) arc (0:-180:\r cm and 0.2*\r cm);
    \draw [dashed]  (S) -- (T)
                    (K) -- (U)
                    (T) arc (0:180:\r cm and 0.2*\r cm)
                    (S) arc (270-\a:270+\a:\R);
\end{tikzpicture}

\end{document}

EDIT

Following a doubt of OP in the comments, when the radius of the cone base is too small, the ellipse is too fat and doesn't reflect the exact reality of a 3D view. It's then possible to change the width of the ellipse to correct this issue:

% Wireframe
        \draw   (T) arc (-90+\a:270-\a:\R);
        \draw   (S) -- (U) -- (T)
                (T) arc (0:-180:\r cm and 0.1*\r cm);
        \draw [dashed]  (S) -- (T)
                        (K) -- (U)
                        (T) arc (0:180:\r cm and 0.1*\r cm)
                        (S) arc (270-\a:270+\a:\R);

Here's what you have with r=3 and the factor is 0.1. with radius r=3

SebGlav
  • 19,186
4

You can use this code. I use 3dtools to draw it.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view=%
    {phi=110,psi=0,theta=70},line join = round, line cap = round,c/.style={circle,fill,inner sep=1pt},
    declare function={R=4;r=3.5;h= sqrt(R*R- r*r);a=asin(r/R);H=r*tan(a); d = h + H;}] 
    \path (0,0,0) coordinate (O) 
    (0,0,-h) coordinate (H)
    (0,0,-d) coordinate (T);
    \path (H)    pic[3d/cone/inner/.style={save named path=cone,draw=none}]{3d/cone={r=r,h=-H}};
    \path[save named path=sph,3d/screen coords] (O) circle[radius=R];
    \tikzset{3d/draw ordered paths={cone,sph}} 
\path foreach \p/\g in {O/90,H/0,T/-90}
    {(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
    \draw[3d/hidden] (T) --(O);
\end{tikzpicture}
\end{document}    

enter image description here

If you use R=5;r=2.5, you get the picture like this.enter image description here

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
    \begin{tikzpicture}[3d/install view=%
        {phi=110,psi=0,theta=70},line join = round, line cap = round,c/.style={circle,fill,inner sep=1pt},
        declare function={R=4;r=3.5;h= sqrt(R*R- r*r);a=asin(r/R);H=r*tan(a); d = h + H;}] 
        \path (0,0,0) coordinate (O) 
        (0,0,-h) coordinate (H)
        (0,0,-d) coordinate (T);
        \path (H)    
        pic[3d/cone/inner/.style={save named path=icone,draw=none},
        3d/cone/outer/.append style={save named path=ocone},
        ]{3d/cone={r=r,h=-H}};
        \path[save named path=sph,3d/screen coords] (O) circle[radius=R];
        \tikzset{3d/draw ordered paths={icone,sph,ocone}} 
        \path foreach \p/\g in {O/90,H/0,T/-90}
        {(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
        \draw[3d/hidden] (T) --(O);
    \end{tikzpicture}
\end{document}

enter image description here

With r =2, we get enter image description here