I have used Tikz to make a cube and now I'd like to make multiple instance of it at different position. Therefore I imaging something like a parameterized pic or a "normal programming function" to reuse my cube.
The problem with the pic is, that I already used a pic to draw parts of the cube. So I would need a pic in a pic.
As parameters I'd like to have the position and ideally orientation of the cube, with both frames fixed in the cube, but rotating with the cube. So ideally there's some kind of grouping and everything rotates with the settings. How can I accomplish this?
Thanks!
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, 3d, calc, decorations.markings,shapes,positioning, backgrounds, scopes}
\usepackage{tikz-3dplot}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{document}
\begin{tikzpicture}[>=latex,scale=1.5,line cap=round, line join =round]
\tikzset{pics/coordsys/.style n args={4}{ code = {
\draw [->, #1] (0,0,0) -- +(1,0,0)[red] node [pos=1.3]{#2};
\draw [->, #1] (0,0,0) -- +(0,1,0)[green!80!black] node [pos=1.2]{#3};
\draw [->, #1] (0,0,0) -- +(0,0,1)[blue] node [pos=1.2]{#4}; } }}
\pgfmathsetmacro{\cubex}{5}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{5}
\newcommand{\boxfillcolor}{yellow!20!}
\newcommand{\boxframecolor}{gray!20!}
\begin{scope}
\draw[\boxframecolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[\boxframecolor] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[\boxframecolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{scope}
\begin{scope}[on background layer]
\fill[\boxfillcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\fill[\boxfillcolor] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\fill[\boxfillcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{scope}
\pgfmathsetmacro{\dx}{0.6};
\pgfmathsetmacro{\dy}{2};
\pgfmathsetmacro{\dz}{0.3};
\coordinate (origin) at (-5,-3,0);
\coordinate (M) at (-\dx,-\cubey/\dy,-\dz);
\coordinate (B) at (-\cubex+\dx,-\cubey/\dy,-\cubez+\dz);
\draw (M) pic {coordsys={thick}{$x_M$}{$y_M$}{$z_M$}};
\node [below right] at (M.south) {\textit{M}};
\draw (B) pic {coordsys={dashed}{$x_M'$}{$y_M'$}{$z_M'$}};
\node [above left] at (B.west) {\textit{B}};
\tdplotsetmaincoords{0}{0};
\tdplotsetrotatedcoords{20}{-60}{10};
\tdplotsetrotatedcoordsorigin{(B)};
\draw [tdplot_rotated_coords] (B) pic {coordsys={thick}{$x_{B}$}{$y_{B}$}{$z_{B}$}};
\draw [->, thick] (M) -- (B) node [midway,fill=\boxfillcolor] {$q_{MB}, r_{MB}$};
\end{tikzpicture}
\end{document}


Markerwhich you did not define. Can you make your code compilable? – Sep 16 '19 at 21:26coordsysbefore.MarkerisM, I'll edit, sorry. – avermaet Sep 16 '19 at 21:29x_Mandy_Mwould be enough + setting the cube/pic position (lets say position of frame M). – avermaet Sep 16 '19 at 21:31