tikz add tag
Anonymous 1123
I see question and answer from [here](https://tex.stackexchange.com/questions/457452/draw-the-four-conic-sections). How to draw intersection of a plane and a cone with `3dtools`?
Top Answer
marmot
Here is a first version. Given a plane that has a slope `alpha` and a cone of fixed base radius and height, you can specify the position of the highest (for `alpha<0`) or lowest (for `alpha>0`) point `I` of the intersection. This point is fixed by its z component `Iz` and a polar angle `gamma`. The intersection curve is then specified. The contour will be terminated when it starts to cross the base circle.

```
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools
\tikzset{pics/3d/intersection of cone with plane/.style={code={
   \def\pv##1{\pgfkeysvalueof{/tikz/3d/intersection of cone with plane/##1}}		
   \tikzset{declare function={%	
    iconeplaneradius(\x,\y,\z)=\z/(1+\y*cos(\x));% https://tex.stackexchange.com/a/457458
	iconeplaneh(\x)=\pv{h}*(\pv{r}-\x)/\pv{r};
   },
    3d/intersection of cone with plane/.cd,#1,
   	e/.evaluated={cos(90+\pv{alpha})/cos(\pv{beta})},
	s/.evaluated={(1+\pv{e})*\pv{r}*(\pv{h}-\pv{Iz})/(\pv{h}*sin(90+\pv{alpha}))},
	beta/.evaluated={atan2(\pv{r},\pv{h})}}
   \pgfmathtruncatemacro{\itest}{(\pv{e}<0.1?0:1)}	
   \ifnum\itest=0\relax
    \pgfmathsetmacro{\tcrit}{180}
   \else
    \pgfmathsetmacro{\tmp}{(\pv{s}-\pv{r})/(\pv{r}*\pv{e})}
	\pgfmathtruncatemacro{\itest}{(abs(\tmp)<1?1:0)}	
	\ifnum\itest=1
	 \pgfmathsetmacro{\tcrit}{abs(acos(\tmp))}
	 %\typeout{tcrit=\tcrit}
	\else
     \pgfmathsetmacro{\tcrit}{180}
	\fi
   \fi
%    \path ({\pv{r}*cos(\pv{gamma})*(\pv{h}-\pv{Iz})/\pv{h}},
%    	{\pv{r}*sin(\pv{gamma})*(\pv{h}-\pv{Iz})/\pv{h}},\pv{Iz}) coordinate (I);
%    \typeout{alpha=\pv{alpha}, beta=\pv{beta}, e=\pv{e}, s=\pv{s}}
%    \pgfmathsetmacro{\Itest}{TD("({iconeplaneradius(0,\pv{e},\pv{s})*cos(0-\pv{gamma})},
%    	{iconeplaneradius(0,\pv{e},\pv{s}))*sin(0-\pv{gamma})},{iconeplaneh(iconeplaneradius(0,\pv{e},\pv{s}))})")}	
%    \path (\Itest) node[dot]{};	
%    \typeout{(Itest)=(\Itest)}	
   \draw[pic actions] plot[variable=\t,domain=-\tcrit:\tcrit,samples=101,smooth]
     ({iconeplaneradius(\t,\pv{e},\pv{s})*cos(\t-\pv{gamma})},
  	{iconeplaneradius(\t,\pv{e},\pv{s}))*sin(\t-\pv{gamma})},
	{iconeplaneh(iconeplaneradius(\t,\pv{e},\pv{s}))});
}},/tikz/3d/intersection of cone with plane/.cd,
		h/.initial=5,% height of the cone
		r/.initial=3,% radius of the base
  		gamma/.initial=0,% angle of intersection
		Iz/.initial=3,% z coordinate of the intersection
		alpha/.initial=0,% slope of the plane
		beta/.initial=0,% will be computed
		e/.initial=1,
		s/.initial=1}
\begin{document}
\begin{tikzpicture}
 \begin{scope}[3d/install view={phi=30,theta=70},
 	declare function={R=3;% radius of the base of the cone
	H=5;% height of the cone
	},
	dot/.style={circle,fill,inner sep=1.2pt,label=above:{#1}}]
  \path 
   (0,0,0) coordinate (O) % center of base of the cone (fixed)
   (0,0,H) coordinate (T); % tip of the cone
%   
  \path (O) pic{3d/cone={r=R,h=H}};
% 
  \begin{scope}[3d/intersection of cone with plane/.cd,r=R,h=H,gamma=-20]
  \path pic[fill=blue]{3d/intersection of cone with plane={Iz=2.75,alpha=-45}};
  \path pic[fill=green!70!black]{3d/intersection of cone with plane={Iz=3,alpha=-30}};
  \path pic[fill=red]{3d/intersection of cone with plane={Iz=3.25,alpha=-15}};
  \path pic[fill=orange]{3d/intersection of cone with plane={Iz=3.5,alpha=0}};
  \end{scope}
 \end{scope}
\end{tikzpicture}
\end{document}
```

![Screen Shot 2020-12-09 at 11.35.15 PM.png](/image?hash=e01da05f5911c0f583baec25e664f78ba9f9860fc95facf7f9b01fa861090938)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.