0

It's a bit complex problem to explain myself, I'll try to do my best.

For this I am going to give an example of a drawing that I already have on tikz. In it, I draw a cuboid with a subcuboid inside, which I then take out of the drawing to place it next to it:

cuboids image

The code I've done it with is as follows:

\begin{figure}[htp]
    \centering
    \begin{tikzpicture}[scale=0.3]
        % Cuboide
        \draw[-] (0,0) -- (0,10);
        \draw[-] (0,10) -- (11.2,10);
        \draw[-] (11.2,10) -- (11.2,0);
        \draw[-] (11.2,0) -- (0,0) node at (6,-1.5) {112};
    \draw[stealth-stealth] (-1,3) -- (-1,10) node at (-2.5,6.5) {85};

    \draw[-] (4.1,4.1) -- (4.1,15.3);
    \draw[-] (4.1,15.3) -- (15.3,15.3);
    \draw[-] (15.3,15.3) -- (15.3,4.1) node at (14,1.4) {71};
    \draw[-] (15.3,4.1) -- (4.1,4.1);       

    \draw[-] (0,0) -- (4.1,4.1);
    \draw[-] (0,10) -- (4.1,15.3);
    \draw[-] (11.2,10) -- (15.3,15.3);
    \draw[-] (11.2,0) -- (15.3,4.1);

    % Subcuboide
    \draw[-] (0,3) -- (11.2,3);
    \draw[-] (4.1,7.1) -- (15.3,7.1);

    \draw[-] (0,3) -- (4.1,7.1);
    \draw[-] (11.2,3) -- (15.3,7.1);

    % Subcuboide independiente
    \draw[-stealth] (16,3) -- (20,3);

    \draw[-] (21,0) -- (32.2,0);
    \draw[-] (21,0) -- (21,3) node at (20,1.4) {15};
    \draw[-] (21,3) -- (32.2,3);        
    \draw[-] (32.2,3) -- (32.2,0);  

    \draw[-] (25.1,4.1) -- (36.3,4.1);
    \draw[-] (25.1,4.1) -- (25.1,7.1);
    \draw[-] (25.1,7.1) -- (36.3,7.1);
    \draw[-] (36.3,7.1) -- (36.3,4.1);

    \draw[-] (21,0) -- (25.1,4.1);
    \draw[-] (32.2,0) -- (36.3,4.1);
    \draw[-] (21,3) -- (25.1,7.1);
    \draw[-] (32.2,3) -- (36.3,7.1);

\end{tikzpicture}

\end{figure}

As you can see, the way to do this is very crude, drawing each line from the coordinates of the axis. For a drawing there are no problems, but in this case when drawing the second cuboid it becomes really tedious (I have to calculate the coordinates that would correspond to it).

Wouldn't there be some way to make a drawing the same, but in which both cuboids (or whatever) start at coordinate 0,0?

1 Answers1

2

A scope can be used for that. Also consider using 3D coordinates like this:

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}[line join=round]
\draw (0,0,0) -- (2,0,0) -- (2,0,2) -- (0,0,2) -- cycle; 
\draw (0,2,0) -- (2,2,0) -- (2,2,2) -- (0,2,2) -- cycle;
\draw (0,0,0) -- (0,2,0) (2,0,0) -- (2,2,0) (0,0,2) -- (0,2,2) (2,0,2) -- (2,2,2); 
\draw (0,0.5,0) -- (2,0.5,0) -- (2,0.5,2) -- (0,0.5,2) -- cycle;
\begin{scope}[xshift=3cm]
\draw (0,0,0) -- (2,0,0) -- (2,0,2) -- (0,0,2) -- cycle; 
\draw (0,0.5,0) -- (2,0.5,0) -- (2,0.5,2) -- (0,0.5,2) -- cycle;
\draw (0,0,0) -- (0,0.5,0) (2,0,0) -- (2,0.5,0) (0,0,2) -- (0,0.5,2) (2,0,2) -- (2,0.5,2); 
\end{scope}
\end{tikzpicture}
\end{document}

A cube and a cuboid

Edit: A color version to show what is what:

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}[line join=round, very thick]
\draw[red]   (0,0,0) -- (2,0,0) -- (2,0,2) -- (0,0,2) -- cycle; 
\draw[green] (0,2,0) -- (2,2,0) -- (2,2,2) -- (0,2,2) -- cycle;
\draw[blue]  (0,0,0) -- (0,2,0) (2,0,0) -- (2,2,0) (0,0,2) -- (0,2,2) (2,0,2) -- (2,2,2); 
\draw[black] (0,0.5,0) -- (2,0.5,0) -- (2,0.5,2) -- (0,0.5,2) -- cycle;
\begin{scope}[xshift=3cm]
\draw[red]   (0,0,0) -- (2,0,0) -- (2,0,2) -- (0,0,2) -- cycle; 
\draw[black] (0,0.5,0) -- (2,0.5,0) -- (2,0.5,2) -- (0,0.5,2) -- cycle;
\draw[teal]  (0,0,0) -- (0,0.5,0) (2,0,0) -- (2,0.5,0) (0,0,2) -- (0,0.5,2) (2,0,2) -- (2,0.5,2); 
\end{scope}
\end{tikzpicture}
\end{document}

A cube and a cuboid with colored lines