2

Here's a sketch, produced with a vector-based drawing app, of the figure that I wish to produce in TikZ:

enter image description here

Here's an initial draft of TikZ, which only shows a 4-sided cone:

\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}

\begin{document}
\tdplotsetmaincoords{70}{100}
\begin{tikzpicture}[tdplot_main_coords] 
  \coordinate (O)  at (0,0,0);
  \coordinate (e1) at (1,0,1);
  \coordinate (e2) at (0,1,1);
  \coordinate (e3) at (-1,0,1);
  \coordinate (e4) at (0,-1,1);

  % Level sets
  \foreach \scale in {1.0,.75,.50,.25}
    \draw[scale=\scale,fill opacity=.5,fill=gray]
      (1,0,0) -- (0,1,0) -- (-1,0,0) -- (0,-1,0) -- cycle;

  % Cone
  \draw (e1) -- (e2) -- (e3) -- (e4)  -- cycle;

  % Extreme rays
  \draw[line join=round,fill,opacity=.7] (O) -- (e1) -- (e2) -- cycle;
  \draw[line join=round,fill,opacity=.7] (O) -- (e1) -- (e4) -- cycle;
  \draw[line join=round,fill,opacity=.5] (O) -- (e4) -- (e3) -- cycle;
  \draw[line join=round,fill,opacity=.5] (O) -- (e3) -- (e2) -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

Is tikz-3dplot the best way to go about this? I'll be glad for pointers on getting the right look.

Update

Thanks to marmot's answer, I was able to produce this illustration:

revised tikz image

And here's marmot's modified code:

\documentclass[10pt,tikz,multi]{standalone}
\usepackage{amsmath,amssymb}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes.geometric}

\begin{document}
\tdplotsetmaincoords{68}{95}
\begin{tikzpicture}[very thin,tdplot_main_coords,line join=round]
  % Draw top of cone
  \begin{scope}[canvas is xy plane at z=6,transform shape]
    \node[regular polygon,regular polygon sides=5,minimum width=6cm](5gon){};
  \end{scope}

  % Level sets
  \begin{scope}[canvas is xy plane at z=0,transform shape]
    \draw (-3,-2.6) rectangle (4,2.6);
    \foreach \X  in {5,4,...,1} {
      \node[draw=black,regular polygon,regular polygon sides=5,
      minimum width=\X cm,fill=gray,fill opacity=0.2](5gon-\X){};
    }
    \node[thick,draw=blue,regular polygon,regular polygon sides=5,draw,minimum
    width=5cm,fill=gray,fill opacity=0.2](5gon-5){};

    % Labels
    \node at (-2.5,2.1) [rotate=90,scale=2] {$\mathbb{R}$};
    \node at (+2.6,-.75) [rotate=90,scale=2] {$\mathcal{C}$};
  \end{scope}

  % Faces of cone
  \foreach \X [count=\Y] in {2,3,4,5,1}
  {\draw \ifnum\Y<4
    [fill=orange] 
    \else 
    [fill=gray,opacity=.9]
    \fi (5gon.corner \Y) -- (0,0,0) -- (5gon.corner \X) -- cycle;}

  % Slice cone at unit level
  \begin{scope}[canvas is xy plane at z=5,transform shape]
    \node[draw=blue,thick,fill=gray,opacity=.4,
          regular polygon,regular polygon sides=5,minimum width=5cm]{};
    \node at (-.5,-.1) [rotate=90,scale=1.2] {$\mathcal{C}\times\{1\}$};
 \end{scope}
\end{tikzpicture}
\end{document}

The lines in the background probably should be dotted, but this version seems fairly complete.

1 Answer 1

6

Yes, I believe that tikz-3dpot is decent choice for this. It autoloads the 3d library with which you can draw stuff in the various planes. You can then draw regular polygons in these planes and connect their corners in 3d.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{amssymb}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes.geometric}
\begin{document}
\tdplotsetmaincoords{70}{100}
\begin{tikzpicture}[tdplot_main_coords,line join=round] 
 \begin{scope}[canvas is xy plane at z=4,transform shape]
  \node[regular polygon,regular polygon sides=5,minimum width=4cm](5gon){};
 \end{scope}
 \begin{scope}[canvas is xy plane at z=0,transform shape]
  \draw (-4,-4) rectangle (4,4);
  \node at(-3,3) [rotate=90,scale=2] {$\mathbb{R}^n$};
  \foreach \X  in {5,4,...,1}
  {\node[regular polygon,regular polygon sides=5,draw,minimum
  width=\X*0.8cm,fill=gray,fill opacity=0.2](5gon-\X){};}
 \end{scope}
  \coordinate (O)  at (0,0,0);
  \foreach \X [count=\Y] in {2,3,4,5,1}
  {\draw \ifnum\Y<4
  [fill=orange] 
  \else 
  [fill=gray]
  \fi (5gon.corner \Y) -- (O) -- (5gon.corner \X) -- cycle;}
\end{tikzpicture}
\end{document}

enter image description here

However, your screen shot seems to have a perspective view. It is possible to draw object with perspective using Max' great recent addition: the perspective library.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{perspective}
\begin{document}
\begin{tikzpicture}[3d view, perspective={q={(0,10,4)}},5gon/.style n args={4}{
  insert path={(tpp cs:x={#1*cos(72*1+#3)},y={#1*sin(72*1+#3)},z=#2)
  coordinate(#4-1)
  foreach \XX in {2,...,5}
  {-- (tpp cs:x={#1*cos(72*\XX+#3)},y={#1*sin(72*\XX+#3)},z=#2) coordinate(#4-\XX)}
  -- cycle}}] 
 \draw[5gon={2}{4}{-40}{upper 5gon}];
 \foreach \X in {1,...,5}
 {\draw[5gon={0.4*\X}{0}{-40}{contour \X}];}
 \draw (tpp cs:x=-3,y=-3,z=0) -- (tpp cs:x=3,y=-3,z=0) 
 -- (tpp cs:x=3,y=3,z=0)-- (tpp cs:x=-3,y=3,z=0) -- cycle;
 \path (tpp cs:x=0,y=0,z=0) coordinate (O);
 \foreach \X [remember=\X as \LastX (initially 5)] in {1,...,5}
  {\draw \ifnum\X<4
  [fill=orange] 
  \else 
  [fill=gray]
  \fi (upper 5gon-\LastX) -- (O) -- (upper 5gon-\X) -- cycle;}
\end{tikzpicture}
\end{document}

enter image description here

or

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{perspective}
\begin{document}
\begin{tikzpicture}[3d view={5}{30},
 perspective={p={(20,0,0)},q={(0,20,0)}},5gon/.style n args={4}{
  insert path={(tpp cs:x={#1*cos(72*1+#3)},y={#1*sin(72*1+#3)},z=#2)
  coordinate(#4-1)
  foreach \XX in {2,...,5}
  {-- (tpp cs:x={#1*cos(72*\XX+#3)},y={#1*sin(72*\XX+#3)},z=#2) coordinate(#4-\XX)}
  -- cycle}}] 
 \draw[5gon={2}{4}{0}{upper 5gon}];
 \foreach \X in {1,...,5}
 {\draw[5gon={0.4*\X}{0}{0}{contour \X}];}
 \draw (tpp cs:x=-3,y=-3,z=0) -- (tpp cs:x=3,y=-3,z=0) 
 -- (tpp cs:x=3,y=3,z=0)-- (tpp cs:x=-3,y=3,z=0) -- cycle;
 \path (tpp cs:x=0,y=0,z=0) coordinate (O);
 \foreach \X [remember=\X as \LastX (initially 5)] in {1,...,5}
  {\draw \ifnum\X<4
  [fill=orange] 
  \else 
  [fill=gray]
  \fi (upper 5gon-\LastX) -- (O) -- (upper 5gon-\X) -- cycle;}
\end{tikzpicture}
\end{document}

enter image description here

1
  • The addition of perspective in the last two examples add a really interesting view that is useful. The complexity of the code is beyond me, unfortunately, and I wouldn't be able to tweak these as needed. Many thanks for the first example, which introduced me to canvas is xy plane and regular polygon.
    – Michael
    Jun 28, 2019 at 5:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .