all.
I've drawn a pentagonal prism using TikZ's 3d library. Here's the code:
\documentclass[tikz,border=1cm]{standalone}
\colorlet{blu}{blue!10}
\usetikzlibrary{3d,
% arrows
}
\begin{document}
\begin{tikzpicture}[opacity=0.8]
\newdimen\len
\len=2cm
%\foreach
\begin{scope}[canvas is zx plane at y=0]
\pgfmathsetmacro{\angle}{360/5}
\draw[fill=blu] %
(0:\len) coordinate (a0)
\foreach \i in {1,...,4} {
-- (\angle*\i:\len) coordinate (a\i)
}
-- cycle;
\end{scope}
\begin{scope}[canvas is zx plane at y=3]
\pgfmathsetmacro{\angle}{360/5}
\draw[fill=blu] %
(0:\len) coordinate (b0)
\foreach \i in {1,...,4} {
-- (\angle*\i:\len) coordinate (b\i)
}
-- cycle;
\end{scope}
\draw (a3) -- (b3);
\draw[fill=blu] (a0) -- node [midway,anchor=north] {$l$} (a4) -- node[midway,anchor=east] {$h$} (b4) -- (b0);
\foreach \q in {0,1}{
\pgfmathsetmacro{\s}{\q + 1}
\draw[fill=blu] (a\s) -- (a\q) -- (b\q) -- (b\s) ;
}
\draw (a2) -- (b2);
\pgfmathsetmacro{\R}{5}
%\coordinate (O) at (0,0,0);
%\foreach \a/\pos in {x/north,y/east,z/west}
% \draw[very thin,->] (O) -- (xyz cs: \a=\R) node[anchor=\pos] {$\a$};
\end{tikzpicture}
Although it works and it looks acceptable, I'd like to optimise this code using loops. Here's another MWE:
\documentclass[tikz,border=1cm]{standalone}
\colorlet{blu}{blue!10}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}
\newdimen\len
\len=2cm
\foreach \i in {1,...,5} {
\begin{scope}[canvas is xz plane at y=0]
\coordinate (a\i) at (\i*360/5:\len);
\end{scope}
\begin{scope}[canvas is xz plane at y=3]
\coordinate (b\i) at (\i*360/5:\len);
\end{scope}
\draw (a\i) -- (b\i);
}
\foreach \q in {a,b}{
\foreach \j in {1,...,4} {
\pgfmathsetmacro\k{\j+1}
\draw (\q\j) -- (\q\k);
}
\draw (\q5) -- (\q1); %LOOP
}
\end{tikzpicture}
\end{document}
This works fine. What I don't know how to do now is how to fill it; I'd also very much like to Loop the drawing of the base pentagons (that's why I added the `%LOOP' comment). In the first example I commented the code for generating axes, but they are eventually going to appear in this figure. Having seen this post, I'd like to point out that I want the prism to be drawn like this, not with the pentagons as foreground and background (it's for a set of notes I'm writing and it is important that the prism be drawn like this).
I know one should ask one question per post, so what I'd really like to solve first is the filling part: how do I fill the faces of the second figure, drawn as it is?
Thanks!

