7

I want to draw a truncated icosahedron:

truncated icosahedron

I've found a code by @Symbol 1

\documentclass[border=9,tikz]{standalone}

\usepackage{tikz-3dplot}

\begin{document}

    \tdplotsetmaincoords{2.71828+\s}{2.71828+\s*2}
    \tikz[tdplot_main_coords,scale=.1]{
        \path(-150cm,-150cm)(150cm,150cm);
        \draw
            (20.1774,0,-97.9432)--(40.3548,-32.6477,-85.4729)--(73.0026,-20.1774,-65.2955)--(73.0026,20.1774,-65.2955)--(40.3548,32.6477,-85.4729)--cycle
            (20.1774,0,97.9432)--(40.3548,32.6477,85.4729)--(73.0026,20.1774,65.2955)--(73.0026,-20.1774,65.2955)--(40.3548,-32.6477,85.4729)--cycle
            (-20.1774,0,97.9432)--(-40.3548,-32.6477,85.4729)--(-73.0026,-20.1774,65.2955)--(-73.0026,20.1774,65.2955)--(-40.3548,32.6477,85.4729)--cycle
            (-20.1774,0,-97.9432)--(-40.3548,32.6477,-85.4729)--(-73.0026,20.1774,-65.2955)--(-73.0026,-20.1774,-65.2955)--(-40.3548,-32.6477,-85.4729)--cycle
            (97.9432,20.1774,0)--(85.4729,40.3548,32.6477)--(65.2955,73.0026,20.1774)--(65.2955,73.0026,-20.1774)--(85.4729,40.3548,-32.6477)--cycle
            (0,97.9432,20.1774)--(32.6477,85.4729,40.3548)--(20.1774,65.2955,73.0026)--(-20.1774,65.2955,73.0026)--(-32.6477,85.4729,40.3548)--cycle
            (-97.9432,20.1774,0)--(-85.4729,40.3548,-32.6477)--(-65.2955,73.0026,-20.1774)--(-65.2955,73.0026,20.1774)--(-85.4729,40.3548,32.6477)--cycle
            (0,97.9432,-20.1774)--(-32.6477,85.4729,-40.3548)--(-20.1774,65.2955,-73.0026)--(20.1774,65.2955,-73.0026)--(32.6477,85.4729,-40.3548)--cycle
            (-97.9432,-20.1774,0)--(-85.4729,-40.3548,32.6477)--(-65.2955,-73.0026,20.1774)--(-65.2955,-73.0026,-20.1774)--(-85.4729,-40.3548,-32.6477)--cycle
            (0,-97.9432,-20.1774)--(32.6477,-85.4729,-40.3548)--(20.1774,-65.2955,-73.0026)--(-20.1774,-65.2955,-73.0026)--(-32.6477,-85.4729,-40.3548)--cycle
            (97.9432,-20.1774,0)--(85.4729,-40.3548,-32.6477)--(65.2955,-73.0026,-20.1774)--(65.2955,-73.0026,20.1774)--(85.4729,-40.3548,32.6477)--cycle
            (0,-97.9432,20.1774)--(-32.6477,-85.4729,40.3548)--(-20.1774,-65.2955,73.0026)--(20.1774,-65.2955,73.0026)--(32.6477,-85.4729,40.3548)--cycle
            (85.4729,40.3548,-32.6477)--(97.9432,20.1774,0)--(97.9432,-20.1774,0)--(85.4729,-40.3548,-32.6477)--(73.0026,-20.1774,-65.2955)--(73.0026,20.1774,-65.2955)--cycle
            (85.4729,-40.3548,32.6477)--(97.9432,-20.1774,0)--(97.9432,20.1774,0)--(85.4729,40.3548,32.6477)--(73.0026,20.1774,65.2955)--(73.0026,-20.1774,65.2955)--cycle
            (-85.4729,40.3548,32.6477)--(-97.9432,20.1774,0)--(-97.9432,-20.1774,0)--(-85.4729,-40.3548,32.6477)--(-73.0026,-20.1774,65.2955)--(-73.0026,20.1774,65.2955)--cycle
            (-85.4729,-40.3548,-32.6477)--(-97.9432,-20.1774,0)--(-97.9432,20.1774,0)--(-85.4729,40.3548,-32.6477)--(-73.0026,20.1774,-65.2955)--(-73.0026,-20.1774,-65.2955)--cycle
            (40.3548,32.6477,-85.4729)--(20.1774,0,-97.9432)--(-20.1774,0,-97.9432)--(-40.3548,32.6477,-85.4729)--(-20.1774,65.2955,-73.0026)--(20.1774,65.2955,-73.0026)--cycle
            (-40.3548,-32.6477,-85.4729)--(-20.1774,0,-97.9432)--(20.1774,0,-97.9432)--(40.3548,-32.6477,-85.4729)--(20.1774,-65.2955,-73.0026)--(-20.1774,-65.2955,-73.0026)--cycle
            (40.3548,-32.6477,85.4729)--(20.1774,0,97.9432)--(-20.1774,0,97.9432)--(-40.3548,-32.6477,85.4729)--(-20.1774,-65.2955,73.0026)--(20.1774,-65.2955,73.0026)--cycle
            (-40.3548,32.6477,85.4729)--(-20.1774,0,97.9432)--(20.1774,0,97.9432)--(40.3548,32.6477,85.4729)--(20.1774,65.2955,73.0026)--(-20.1774,65.2955,73.0026)--cycle
            (32.6477,85.4729,-40.3548)--(0,97.9432,-20.1774)--(0,97.9432,20.1774)--(32.6477,85.4729,40.3548)--(65.2955,73.0026,20.1774)--(65.2955,73.0026,-20.1774)--cycle
            (-32.6477,85.4729,40.3548)--(0,97.9432,20.1774)--(0,97.9432,-20.1774)--(-32.6477,85.4729,-40.3548)--(-65.2955,73.0026,-20.1774)--(-65.2955,73.0026,20.1774)--cycle
            (-32.6477,-85.4729,-40.3548)--(0,-97.9432,-20.1774)--(0,-97.9432,20.1774)--(-32.6477,-85.4729,40.3548)--(-65.2955,-73.0026,20.1774)--(-65.2955,-73.0026,-20.1774)--cycle
            (32.6477,-85.4729,40.3548)--(0,-97.9432,20.1774)--(0,-97.9432,-20.1774)--(32.6477,-85.4729,-40.3548)--(65.2955,-73.0026,-20.1774)--(65.2955,-73.0026,20.1774)--cycle
            (20.1774,65.2955,-73.0026)--(32.6477,85.4729,-40.3548)--(65.2955,73.0026,-20.1774)--(85.4729,40.3548,-32.6477)--(73.0026,20.1774,-65.2955)--(40.3548,32.6477,-85.4729)--cycle
            (85.4729,40.3548,32.6477)--(73.0026,20.1774,65.2955)--(40.3548,32.6477,85.4729)--(20.1774,65.2955,73.0026)--(32.6477,85.4729,40.3548)--(65.2955,73.0026,20.1774)--cycle
            (-73.0026,20.1774,65.2955)--(-40.3548,32.6477,85.4729)--(-20.1774,65.2955,73.0026)--(-32.6477,85.4729,40.3548)--(-65.2955,73.0026,20.1774)--(-85.4729,40.3548,32.6477)--cycle
            (-85.4729,40.3548,-32.6477)--(-65.2955,73.0026,-20.1774)--(-32.6477,85.4729,-40.3548)--(-20.1774,65.2955,-73.0026)--(-40.3548,32.6477,-85.4729)--(-73.0026,20.1774,-65.2955)--cycle
            (-85.4729,-40.3548,32.6477)--(-65.2955,-73.0026,20.1774)--(-32.6477,-85.4729,40.3548)--(-20.1774,-65.2955,73.0026)--(-40.3548,-32.6477,85.4729)--(-73.0026,-20.1774,65.2955)--cycle
            (-20.1774,-65.2955,-73.0026)--(-32.6477,-85.4729,-40.3548)--(-65.2955,-73.0026,-20.1774)--(-85.4729,-40.3548,-32.6477)--(-73.0026,-20.1774,-65.2955)--(-40.3548,-32.6477,-85.4729)--cycle
            (85.4729,-40.3548,-32.6477)--(65.2955,-73.0026,-20.1774)--(32.6477,-85.4729,-40.3548)--(20.1774,-65.2955,-73.0026)--(40.3548,-32.6477,-85.4729)--(73.0026,-20.1774,-65.2955)--cycle
            (20.1774,-65.2955,73.0026)--(32.6477,-85.4729,40.3548)--(65.2955,-73.0026,20.1774)--(85.4729,-40.3548,32.6477)--(73.0026,-20.1774,65.2955)--(40.3548,-32.6477,85.4729)--cycle;
    }

\end{document}

texfoot

I just need to color the faces like the first one.

1 Answer 1

7

Luckily this is the same problem as drawing a fullerene. That is, it seems that Nature got inspired in their choices for molecules by soccer balls. ;-) So the answer is yes.

In order to run the following code, you need to download tikzlibrary3dtools.code.tex from this repository, and put the file somewhere where LaTeX will find it, such as the directory in which the file containing the following code is.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds,3dtools}
\makeatletter
% slightly improved (?) version of dim from pgfmathfunctions.misc.code.tex
% at least in this application dim does not give the right results
\pgfmathdeclarefunction{mdim}{1}{%
  \begingroup
    \pgfmath@count=0\relax
    \expandafter\pgfmath@mdim@i#1\pgfmath@token@stop
    \edef\pgfmathresult{\the\pgfmath@count}%
    \pgfmath@smuggleone\pgfmathresult%
  \endgroup}
\def\pgfmath@mdim@i#1{%
    \ifx\pgfmath@token@stop#1%
    \else
      \advance\pgfmath@count by 1\relax
      \expandafter\pgfmath@mdim@i
    \fi}  
%membership test    
\pgfmathdeclarefunction{memberQ}{2}{%
  \begingroup%
    \edef\pgfutil@tmpb{0}%memberQ({\lstPast},\inow)
    \edef\pgfutil@tmpa{#2}%
    \expandafter\pgfmath@member@i#1\pgfmath@token@stop
    \edef\pgfmathresult{\pgfutil@tmpb}%
    \pgfmath@smuggleone\pgfmathresult%
  \endgroup}
\def\pgfmath@member@i#1{%
    \ifx\pgfmath@token@stop#1%
    \else
      \edef\pgfutil@tmpc{#1}%
      \ifx\pgfutil@tmpc\pgfutil@tmpa\relax%
      \gdef\pgfutil@tmpb{1}%
      \fi%
      \expandafter\pgfmath@member@i
    \fi}        
\makeatother    
% 
\begin{document}
\tdplotsetmaincoords{70}{0}
\begin{tikzpicture}[tdplot_main_coords,line cap=round,line join=round]
\path foreach \Coord [count=\X] in {(-0.16246,-2.11803,1.27598),
 (-0.16246,2.11803,1.27598),(0.16246,-2.11803,-1.27598),(0.16246,2.11803,-1.27598),
 (-0.262866,-0.809017,-2.32744),(-0.262866,-2.42705,-0.425325),(-0.262866,0.809017,-2.32744),
 (-0.262866,2.42705,-0.425325),(0.262866,-0.809017,2.32744),(0.262866,-2.42705,0.425325),
 (0.262866,0.809017,2.32744),(0.262866,2.42705,0.425325),(0.688191,-0.5,-2.32744),
 (0.688191,0.5,-2.32744),(1.21392,-2.11803,0.425325),(1.21392,2.11803,0.425325),
 (-2.06457,-0.5,1.27598),(-2.06457,0.5,1.27598),(-1.37638,-1.,1.80171),
 (-1.37638,1.,1.80171),(-1.37638,-1.61803,-1.27598),(-1.37638,1.61803,-1.27598),
 (-0.688191,-0.5,2.32744),(-0.688191,0.5,2.32744),(1.37638,-1.,-1.80171),
 (1.37638,1.,-1.80171),(1.37638,-1.61803,1.27598),(1.37638,1.61803,1.27598),
 (-1.7013,0.,-1.80171),(1.7013,0.,1.80171),(-1.21392,-2.11803,-0.425325),
 (-1.21392,2.11803,-0.425325),(-1.96417,-0.809017,-1.27598),(-1.96417,0.809017,-1.27598),
 (2.06457,-0.5,-1.27598),(2.06457,0.5,-1.27598),(2.22703,-1.,-0.425325),
 (2.22703,1.,-0.425325),(2.38949,-0.5,0.425325),(2.38949,0.5,0.425325),
 (-1.11352,-1.80902,1.27598),(-1.11352,1.80902,1.27598),(1.11352,-1.80902,-1.27598),
 (1.11352,1.80902,-1.27598),(-2.38949,-0.5,-0.425325),(-2.38949,0.5,-0.425325),
 (-1.63925,-1.80902,0.425325),(-1.63925,1.80902,0.425325),(1.63925,-1.80902,-0.425325),
 (1.63925,1.80902,-0.425325),(1.96417,-0.809017,1.27598),(1.96417,0.809017,1.27598),
 (0.850651,0.,2.32744),(-2.22703,-1.,0.425325),(-2.22703,1.,0.425325),
 (-0.850651,0.,-2.32744),(-0.525731,-1.61803,-1.80171),(-0.525731,1.61803,-1.80171),
 (0.525731,-1.61803,1.80171),(0.525731,1.61803,1.80171)}
  {\Coord coordinate (p\X) \pgfextra{\xdef\NumVertices{\X}}};
 %\message{number of vertices is \NumVertices^^J} 
 % normal of screen 
 \path[overlay] ({sin(\tdplotmaintheta)*sin(\tdplotmainphi)},
    {-1*sin(\tdplotmaintheta)*cos(\tdplotmainphi)},
    {cos(\tdplotmaintheta)}) coordinate (n)
    (1,1,1)  coordinate (L); 
 \edef\lstPast{0}
 \foreach \poly in 
 {{53, 11, 24, 23, 9}, {51, 39, 40, 52, 30}, {60, 28, 16, 12, 2}, {20, 
  42, 48, 55, 18}, {19, 17, 54, 47, 41}, {1, 10, 15, 27, 59}, {36, 26,
   44, 50, 38}, {4, 58, 22, 32, 8}, {34, 29, 33, 45, 46}, {21, 57, 3, 
  6, 31}, {37, 49, 43, 25, 35}, {13, 5, 56, 7, 14}, {9, 59, 27, 51, 
  30, 53}, {53, 30, 52, 28, 60, 11}, {11, 60, 2, 42, 20, 24}, {24, 20,
   18, 17, 19, 23}, {23, 19, 41, 1, 59, 9}, {13, 25, 43, 3, 57, 
  5}, {5, 57, 21, 33, 29, 56}, {56, 29, 34, 22, 58, 7}, {7, 58, 4, 44,
   26, 14}, {14, 26, 36, 35, 25, 13}, {40, 38, 50, 16, 28, 52}, {16, 
  50, 44, 4, 8, 12}, {12, 8, 32, 48, 42, 2}, {48, 32, 22, 34, 46, 
  55}, {55, 46, 45, 54, 17, 18}, {54, 45, 33, 21, 31, 47}, {47, 31, 6,
   10, 1, 41}, {10, 6, 3, 43, 49, 15}, {15, 49, 37, 39, 51, 27}, {39, 
  37, 35, 36, 38, 40}}
 {
  \pgfmathtruncatemacro{\ione}{{\poly}[0]}
  \pgfmathtruncatemacro{\itwo}{{\poly}[1]}
  \pgfmathtruncatemacro{\ithree}{{\poly}[2]}
  \path[overlay,3d coordinate={(dA)=(p\itwo)-(p\ione)},
   3d coordinate={(dB)=(p\itwo)-(p\ithree)},
   3d coordinate={(nA)=(dA)x(dB)}];
  \pgfmathtruncatemacro{\jtest}{sign(TD("(nA)o(p\ione)"))}
  % make sure that the normal points outwards
  \ifnum\jtest<0
   \path[overlay,3d coordinate={(nA)=(dB)x(dA)}];
  \fi
  % compute projection the normal of the polygon on the normal of screen    
  \pgfmathsetmacro\myproj{TD("(nA)o(n)")}
  \pgfmathsetmacro\lproj{TD("(nA)o(L)")}
  \pgfmathtruncatemacro{\itest}{sign(\myproj)}
  \pgfmathtruncatemacro{\cf}{70+20*\lproj}
  \pgfmathtruncatemacro{\mydim}{mdim(\poly)}
  \ifnum\itest>-1 
   \draw[ultra thin] \ifnum\mydim=6 [fill=red!\cf!black]
   \else [fill=black]
   \fi
   plot[samples at=\poly,variable=\x](p\x) -- cycle; 
  \else
   \begin{scope}[on background layer] 
    \draw[gray!20,ultra thin] \ifnum\mydim=6 [fill=red!\cf!black]
   \else [fill=black]
   \fi
    plot[samples at=\poly,variable=\x](p\x) -- cycle;  
   \end{scope}
  \fi
  }  
\end{tikzpicture}
\end{document}

enter image description here

This is an animated version.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds,3dtools}
\makeatletter
% slightly improved (?) version of dim from pgfmathfunctions.misc.code.tex
% at least in this application dim does not give the right results
\pgfmathdeclarefunction{mdim}{1}{%
  \begingroup
    \pgfmath@count=0\relax
    \expandafter\pgfmath@mdim@i#1\pgfmath@token@stop
    \edef\pgfmathresult{\the\pgfmath@count}%
    \pgfmath@smuggleone\pgfmathresult%
  \endgroup}
\def\pgfmath@mdim@i#1{%
    \ifx\pgfmath@token@stop#1%
    \else
      \advance\pgfmath@count by 1\relax
      \expandafter\pgfmath@mdim@i
    \fi}  
%membership test    
\pgfmathdeclarefunction{memberQ}{2}{%
  \begingroup%
    \edef\pgfutil@tmpb{0}%memberQ({\lstPast},\inow)
    \edef\pgfutil@tmpa{#2}%
    \expandafter\pgfmath@member@i#1\pgfmath@token@stop
    \edef\pgfmathresult{\pgfutil@tmpb}%
    \pgfmath@smuggleone\pgfmathresult%
  \endgroup}
\def\pgfmath@member@i#1{%
    \ifx\pgfmath@token@stop#1%
    \else
      \edef\pgfutil@tmpc{#1}%
      \ifx\pgfutil@tmpc\pgfutil@tmpa\relax%
      \gdef\pgfutil@tmpb{1}%
      \fi%
      \expandafter\pgfmath@member@i
    \fi}        
\makeatother    
% 
\begin{document}
\foreach \Angle in {0,5,...,355}
{\tdplotsetmaincoords{90+30*sin(2*\Angle)}{\Angle}
\begin{tikzpicture}[tdplot_main_coords,line cap=round,line join=round]
\path foreach \Coord [count=\X] in {(-0.16246,-2.11803,1.27598),
 (-0.16246,2.11803,1.27598),(0.16246,-2.11803,-1.27598),(0.16246,2.11803,-1.27598),
 (-0.262866,-0.809017,-2.32744),(-0.262866,-2.42705,-0.425325),(-0.262866,0.809017,-2.32744),
 (-0.262866,2.42705,-0.425325),(0.262866,-0.809017,2.32744),(0.262866,-2.42705,0.425325),
 (0.262866,0.809017,2.32744),(0.262866,2.42705,0.425325),(0.688191,-0.5,-2.32744),
 (0.688191,0.5,-2.32744),(1.21392,-2.11803,0.425325),(1.21392,2.11803,0.425325),
 (-2.06457,-0.5,1.27598),(-2.06457,0.5,1.27598),(-1.37638,-1.,1.80171),
 (-1.37638,1.,1.80171),(-1.37638,-1.61803,-1.27598),(-1.37638,1.61803,-1.27598),
 (-0.688191,-0.5,2.32744),(-0.688191,0.5,2.32744),(1.37638,-1.,-1.80171),
 (1.37638,1.,-1.80171),(1.37638,-1.61803,1.27598),(1.37638,1.61803,1.27598),
 (-1.7013,0.,-1.80171),(1.7013,0.,1.80171),(-1.21392,-2.11803,-0.425325),
 (-1.21392,2.11803,-0.425325),(-1.96417,-0.809017,-1.27598),(-1.96417,0.809017,-1.27598),
 (2.06457,-0.5,-1.27598),(2.06457,0.5,-1.27598),(2.22703,-1.,-0.425325),
 (2.22703,1.,-0.425325),(2.38949,-0.5,0.425325),(2.38949,0.5,0.425325),
 (-1.11352,-1.80902,1.27598),(-1.11352,1.80902,1.27598),(1.11352,-1.80902,-1.27598),
 (1.11352,1.80902,-1.27598),(-2.38949,-0.5,-0.425325),(-2.38949,0.5,-0.425325),
 (-1.63925,-1.80902,0.425325),(-1.63925,1.80902,0.425325),(1.63925,-1.80902,-0.425325),
 (1.63925,1.80902,-0.425325),(1.96417,-0.809017,1.27598),(1.96417,0.809017,1.27598),
 (0.850651,0.,2.32744),(-2.22703,-1.,0.425325),(-2.22703,1.,0.425325),
 (-0.850651,0.,-2.32744),(-0.525731,-1.61803,-1.80171),(-0.525731,1.61803,-1.80171),
 (0.525731,-1.61803,1.80171),(0.525731,1.61803,1.80171)}
  {\Coord coordinate (p\X) \pgfextra{\xdef\NumVertices{\X}}};
 %\message{number of vertices is \NumVertices^^J} 
 % normal of screen and "light source"
 \path[overlay] ({sin(\tdplotmaintheta)*sin(\tdplotmainphi)},
    {-1*sin(\tdplotmaintheta)*cos(\tdplotmainphi)},
    {cos(\tdplotmaintheta)}) coordinate (n)
    ({sin(\tdplotmaintheta+20)*sin(\tdplotmainphi+40)},
    {-1*sin(\tdplotmaintheta+20)*cos(\tdplotmainphi+40)},
    {cos(\tdplotmaintheta+20)})  coordinate (L);; 
 \edef\lstPast{0}
 \foreach \poly in 
 {{53, 11, 24, 23, 9}, {51, 39, 40, 52, 30}, {60, 28, 16, 12, 2}, {20, 
  42, 48, 55, 18}, {19, 17, 54, 47, 41}, {1, 10, 15, 27, 59}, {36, 26,
   44, 50, 38}, {4, 58, 22, 32, 8}, {34, 29, 33, 45, 46}, {21, 57, 3, 
  6, 31}, {37, 49, 43, 25, 35}, {13, 5, 56, 7, 14}, {9, 59, 27, 51, 
  30, 53}, {53, 30, 52, 28, 60, 11}, {11, 60, 2, 42, 20, 24}, {24, 20,
   18, 17, 19, 23}, {23, 19, 41, 1, 59, 9}, {13, 25, 43, 3, 57, 
  5}, {5, 57, 21, 33, 29, 56}, {56, 29, 34, 22, 58, 7}, {7, 58, 4, 44,
   26, 14}, {14, 26, 36, 35, 25, 13}, {40, 38, 50, 16, 28, 52}, {16, 
  50, 44, 4, 8, 12}, {12, 8, 32, 48, 42, 2}, {48, 32, 22, 34, 46, 
  55}, {55, 46, 45, 54, 17, 18}, {54, 45, 33, 21, 31, 47}, {47, 31, 6,
   10, 1, 41}, {10, 6, 3, 43, 49, 15}, {15, 49, 37, 39, 51, 27}, {39, 
  37, 35, 36, 38, 40}}
 {
  \pgfmathtruncatemacro{\ione}{{\poly}[0]}
  \pgfmathtruncatemacro{\itwo}{{\poly}[1]}
  \pgfmathtruncatemacro{\ithree}{{\poly}[2]}
  \path[overlay,3d coordinate={(dA)=(p\itwo)-(p\ione)},
   3d coordinate={(dB)=(p\itwo)-(p\ithree)},
   3d coordinate={(nA)=(dA)x(dB)}];
  \pgfmathtruncatemacro{\jtest}{sign(TD("(nA)o(p\ione)"))}
  % make sure that the normal points outwards
  \ifnum\jtest<0
   \path[overlay,3d coordinate={(nA)=(dB)x(dA)}];
  \fi
  % compute projection the normal of the polygon on the normal of screen    
  \pgfmathsetmacro\myproj{TD("(nA)o(n)")}
  \pgfmathsetmacro\lproj{TD("(nA)o(L)")}
  \pgfmathtruncatemacro{\itest}{sign(\myproj)}
  \pgfmathtruncatemacro{\cf}{70+20*\lproj}
  \pgfmathtruncatemacro{\mydim}{mdim(\poly)}
  \ifnum\itest>-1 
   \draw[ultra thin] \ifnum\mydim=6 [fill=red!\cf!black]
   \else [fill=black]
   \fi
   plot[samples at=\poly,variable=\x](p\x) -- cycle; 
  \else
   \begin{scope}[on background layer] 
    \draw[gray!20,ultra thin] \ifnum\mydim=6 [fill=red!\cf!black]
   \else [fill=black]
   \fi
    plot[samples at=\poly,variable=\x](p\x) -- cycle;  
   \end{scope}
  \fi
  }  
\end{tikzpicture}}
\end{document}

enter image description here

Notice that this varies both phi and theta to show that it works for all view angles. Since we do not really rotate the object but only change the view angles, we need to move the light source, (L), to achieve the illusion of rotating the polyhedron.

5
  • I can't compile it
    – Math 512
    Dec 1, 2019 at 16:22
  • @Math512 Did you download tikzlibrary3dtools.code.tex from here and copy the file into the same folder as the TeX file you are compiling? What is the error message that you get?
    – user194703
    Dec 1, 2019 at 16:26
  • now I did but it still not working
    – Math 512
    Dec 1, 2019 at 16:44
  • .e-line"><span class="pl-k">\usepackage</ span>{<span class="pl-c1">...
    – Math 512
    Dec 1, 2019 at 16:59
  • @Math512 Sorry, this looks more like a html code than a LaTEX error message to me.
    – user194703
    Dec 1, 2019 at 17:04

You must log in to answer this question.

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