1

I this example:

\documentclass[border=2mm]{standalone}
\usepackage    {tikz}
\usepackage    {siunitx} 
\usetikzlibrary{3d}      
\usetikzlibrary{babel}   
\usetikzlibrary{calc}    

% \usepackage{enumitem,setspace,kantlipsum}
% isometric
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zy{sqrt(2/3)}

\begin{document}
\begin{tikzpicture}[x={(\xx cm,-\xy cm)},y={(\xx cm,\xy cm)},z={(0 cm,\zy cm)},% vectores i,j,k
                    thick,line cap=round,line join=round, scale=0.7]

\def\br{1.5}  
\def\be{4}    

\def\we{17.6} 
\def\ws{4}    


\fill[canvas is yz plane at x=-\ws,gray!30] (-1.2*\ws,0)    rectangle (1.2*\ws,\we+1); 
\fill[canvas is xy plane at z=0   ,gray!15] (-\ws,-1.2*\ws) rectangle (7,1.2*\ws); 
\draw[dashed] (0,0,\be) -- (0,0,0) -- (\ws,0,0)  node[midway,sloped, above, xshift=-0.65cm] {\SI{40}{cm}};
\fill[canvas is xy plane at z=0,gray!80] (\ws,0) circle (0.25) node[black,xshift=1.25cm] {}; %
\draw[canvas is xy plane at z=0,cyan, dashed] (\ws,0) circle (2.25) node[black,xshift=0.85cm, align=left] {Boxing\\ Zone};


\draw[fill= red!20] ($(-135:\br)+(0,0,\be+9.6)$) --++ (0,0,-9.6)
    {[canvas is xy plane at z=\be] arc (-135:45:\br)} -- ($(45:\br)+(0,0,\be+9.6)$);

\draw[canvas is xy plane at z=\be+9.6,fill=red!40] (0,0) circle (\br);

\foreach[count=\xi]\i in{1.5,4.2,6.9}
{%                       1.5, 1.5+2.7, 1.5+2.7+2.7
  \begin{scope}[canvas is xy plane at z=\be+\i] 
    \draw[orange] (0,0) circle (\br);
    \fill[orange] (0,0,\be+\i) circle (1pt); 
    \coordinate   (C\xi) at (225:\br+0.2); 
    %--
    \foreach \k in {0,120,240}
    {%
      \begin{scope}[rotate=\k]  
        \draw[gray,dashed] (0,0) -- (\br,0);
        \draw[red, opacity=0.85, fill=blue!75,fill opacity=0.6,] (0.75,-0.12) rectangle (1.1,0.12);
      \end{scope}
    }
    %--
  \end{scope}
}

\foreach\i in {0,90,180,270}
{%
  \draw[line width=0.5mm] ($(\i:\br)+(0,0,\be+9.6)$) -- (0,0,\we-0.15);
}
\draw[line width=0.5mm] (0,-\br,\be+9.6) --++ (0,0,-0.5); 
\draw[line width=0.5mm] (\br, 0,\be+9.6) --++ (0,0,-0.5); 
% Wall structure
\begin{scope}[shift={(-\ws,0,\we)},line width=1.5mm]
  \draw (0.5*\ws ,0,0) -- (0,0,-0.5*\ws) -- (0,0,-\ws); 
  \draw (0,-0.5*\ws,0) -- (0,0.5*\ws,0); 
  \draw (0,0,0)        -- (1.25*\ws,0,0);
 
\end{scope}


\end{tikzpicture}
\end{document}

I would like to change the angle \k of the sections which are plotted with:

    %--
    \foreach \k in {0,120,240}
    {%
      \begin{scope}[rotate=\k]  
        \draw[gray,dashed] (0,0) -- (\br,0);
        \draw[red, opacity=0.85, fill=blue!75,fill opacity=0.6,] (0.75,-0.12) rectangle (1.1,0.12);
      \end{scope}
    }
    %--

as a function of the foreach with index \i (\foreach[count=\xi]\i in{1.5,4.2,6.9}) For example, if the value of \i is 1.5 (the first value of the list) do nothing but if the values are 4.2 or 6.9 then the rotation given by angle \k should change to 60, 180, and 300 degrees.

5
  • It's unclear what you mean. What does the value of \i have to do with \k?
    – Someone
    Commented May 25, 2021 at 21:20
  • @Someone \i is the height of the horizontal sections in the boxing bag and \kare the angles of the radius (the three dashed lines). What I would like is to change \k as a function of \i.
    – pablo
    Commented May 25, 2021 at 21:23
  • Did you mean 60, 180, 300? Commented May 25, 2021 at 22:11
  • 1
    \foreach [evaluate={\kk={ifthenelse(\i<4, \k, \k+60)}}] \k in {0,120,240} { \begin{scope}[rotate=\kk] will do that. If \i is less than 4, set \kk to \k, otherwise set it to \k+60. Commented May 25, 2021 at 22:15
  • @TorbjørnT. It works fine. Thank you.
    – pablo
    Commented May 26, 2021 at 8:17

1 Answer 1

1

In short:

\foreach [evaluate={\kk={ifthenelse(\i<4, \k, \k+60)}}] \k in {0,120,240}    
    {       
      \begin{scope}[rotate=\kk]

evaluate lets you calculate a new value based on the loop variable. So here I use ifthenelse to check the value of \i, and set the new variable \kk to either \k or \k+60.

enter image description here

\documentclass[border=2mm]{standalone}
\usepackage    {tikz}
\usepackage    {siunitx} 
\usetikzlibrary{3d}      
\usetikzlibrary{babel}   
\usetikzlibrary{calc}    

% \usepackage{enumitem,setspace,kantlipsum}
% isometric
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zy{sqrt(2/3)}

\begin{document}
\begin{tikzpicture}[x={(\xx cm,-\xy cm)},y={(\xx cm,\xy cm)},z={(0 cm,\zy cm)},% vectores i,j,k
                    thick,line cap=round,line join=round, scale=0.7]

\def\br{1.5}  
\def\be{4}    

\def\we{17.6} 
\def\ws{4}    


\fill[canvas is yz plane at x=-\ws,gray!30] (-1.2*\ws,0)    rectangle (1.2*\ws,\we+1); 
\fill[canvas is xy plane at z=0   ,gray!15] (-\ws,-1.2*\ws) rectangle (7,1.2*\ws); 
\draw[dashed] (0,0,\be) -- (0,0,0) -- (\ws,0,0)  node[midway,sloped, above, xshift=-0.65cm] {\SI{40}{cm}};
\fill[canvas is xy plane at z=0,gray!80] (\ws,0) circle (0.25) node[black,xshift=1.25cm] {}; %
\draw[canvas is xy plane at z=0,cyan, dashed] (\ws,0) circle (2.25) node[black,xshift=0.85cm, align=left] {Boxing\\ Zone};


\draw[fill= red!20] ($(-135:\br)+(0,0,\be+9.6)$) --++ (0,0,-9.6)
    {[canvas is xy plane at z=\be] arc (-135:45:\br)} -- ($(45:\br)+(0,0,\be+9.6)$);

\draw[canvas is xy plane at z=\be+9.6,fill=red!40] (0,0) circle (\br);

\foreach[count=\xi]\i in{1.5,4.2,6.9}
{%                       1.5, 1.5+2.7, 1.5+2.7+2.7
  \begin{scope}[canvas is xy plane at z=\be+\i] 
    \draw[orange] (0,0) circle (\br);
    \fill[orange] (0,0,\be+\i) circle (1pt); 
    \coordinate   (C\xi) at (225:\br+0.2); 
    %--
\foreach [evaluate={\kk={ifthenelse(\i<4, \k, \k+60)}}] \k in {0,120,240}    
    {       
      \begin{scope}[rotate=\kk]
        \draw[gray,dashed] (0,0) -- (\br,0);
        \draw[red, opacity=0.85, fill=blue!75,fill opacity=0.6,] (0.75,-0.12) rectangle (1.1,0.12);
      \end{scope}
    }
    %--
  \end{scope}
}

\foreach\i in {0,90,180,270}
{%
  \draw[line width=0.5mm] ($(\i:\br)+(0,0,\be+9.6)$) -- (0,0,\we-0.15);
}
\draw[line width=0.5mm] (0,-\br,\be+9.6) --++ (0,0,-0.5); 
\draw[line width=0.5mm] (\br, 0,\be+9.6) --++ (0,0,-0.5); 
% Wall structure
\begin{scope}[shift={(-\ws,0,\we)},line width=1.5mm]
  \draw (0.5*\ws ,0,0) -- (0,0,-0.5*\ws) -- (0,0,-\ws); 
  \draw (0,-0.5*\ws,0) -- (0,0.5*\ws,0); 
  \draw (0,0,0)        -- (1.25*\ws,0,0);
 
\end{scope}


\end{tikzpicture}
\end{document}

You must log in to answer this question.

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