4

Is there any more practical way to do this drawing using the lengths and widths so that I do not need to set all the vertices as I did?

\documentclass[landscape]{article}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
%%%>
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A1) at (0,0);
\coordinate (A2) at (35,0);
\coordinate (A3) at (35,17);
\coordinate (A4) at (0,17);

\draw[thick] (A1) -- (A2);
\draw[thick] (A1) -- (A4);
\draw[thick] (A3) -- (A4);

\coordinate (A5) at (35,-2);
\coordinate (A6) at (70,-2);
\coordinate (A7) at (70,19);
\coordinate (A8) at (35,19);

\draw[thick] (A5) -- (A6);
\draw[thick] (A6) -- (A7);
\draw[thick] (A7) -- (A8);
\draw[thick] (A8) -- (A5);

\coordinate (A9) at (70,0);
\coordinate (A10) at (125,0);
\coordinate (A11) at (125,17);
\coordinate (A12) at (70,17);

\draw[thick] (A9) -- (A10);
\draw[thick] (A10) -- (A11);
\draw[thick] (A11) -- (A12);

\end{tikzpicture}
\end{document}

enter image description here

1 Answer 1

8

You can make better use of coordinate and calc. Here I do not have any absolute coordinates to draw the axle:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[x=1mm,y=1mm,>=latex]
  \coordinate (ALL); %% Lower left of 1st axle
  \coordinate (BLL) at ($(ALL) + (35,-2)$); %% Lower left of 2nd axle
  \coordinate (CLL) at ($(ALL) + (70,0)$); %% Lower left of 3rd axle
  \draw[thick] (ALL) rectangle +(35,17) coordinate (AUR); %% Upper right corner of 1st axle
  \draw[thick] (BLL) rectangle +(35,21) coordinate (BUR); %% Upper right corner of 2nd axle
  \draw[thick] (CLL) rectangle +(55,17) coordinate (CUR); %% Upper right corner of 2nd axle
\end{tikzpicture}
\end{document}

The same coordinates can be used to draw the measures. It becomes a bit more complicated but with use of (Coor1 -| Coor2) to get the coordinate horizontally from Coor1 and vertically from Coor2 it is doable.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[x=1mm,y=1mm,>=latex]
  \coordinate (ALL); %% Lower left of 1st axle
  \coordinate (BLL) at ($(ALL) + (35,-2)$); %% Lower left of 2nd axle
  \coordinate (CLL) at ($(ALL) + (70,0)$); %% Lower left of 3rd axle
  \draw[thick] (ALL) rectangle +(35,17) coordinate (AUR); %% Upper right corner of 1st axle
  \draw[thick] (BLL) rectangle +(35,21) coordinate (BUR); %% Upper right corner of 2nd axle
  \draw[thick] (CLL) rectangle +(55,17) coordinate (CUR); %% Upper right corner of 2nd axle
  %% Measures
  \coordinate (Mx1) at ($(BLL) + (-35-15,0)$);
  \coordinate (Mx2) at ($(BLL) + (-35-10,0)$);
  \coordinate (Mx3) at ($(BLL) + (35+55+10,0)$);
  \coordinate (My1) at ($(BLL) + (0,-10)$);
  %% 21
  \draw ($(BLL)+(-1,0)$) -- ($(Mx1)+(-1,0)$);
  \draw ($(BLL)+(-1,21)$) -- ($(Mx1)+(-1,21)$);
  \draw[<->] (Mx1) -- ($(Mx1)+(0,21)$) node[pos=0.5,anchor=south,rotate=90]{21};
  %% 2
  \draw ($(ALL)+(-1,0)$) -- ($(Mx2 |- ALL) + (-1,0)$);
  \draw[<-] (Mx2 |- BLL) -- +(0,-5) node[pos=0.5,anchor=south,rotate=90]{2};
  \draw[<-] (Mx2 |- ALL) -- +(0,5);
  %% 35 35 55
  \draw ($(ALL)+(0,-1)$) -- ($(My1 -| ALL)+(0,-1)$);
  \draw ($(BLL)+(0,-1)$) -- ($(My1 -| BLL)+(0,-1)$);
  \draw ($(BUR |- BLL)+(0,-1)$) -- ($(My1 -| BUR)+(0,-1)$);
  \draw ($(CUR |- CLL)+(0,-1)$) -- ($(My1 -| CUR)+(0,-1)$);
  \draw[<->] (My1 -| ALL) -- (My1 -| BLL) node[anchor=south,pos=0.5]{35};
  \draw[<->] (My1 -| BLL) -- (My1 -| CLL) node[anchor=south,pos=0.5]{35};
  \draw[<->] (My1 -| CLL) -- (My1 -| CUR) node[anchor=south,pos=0.5]{55};
  %% 17
  \draw ($(CUR) + (1,0)$) -- ($(CUR -| Mx3)+(1,0)$);
  \draw ($(CUR |- CLL) + (1,0)$) -- ($(CLL -| Mx3)+(1,0)$);
  \draw[<->] (Mx3 |- CLL) -- (Mx3 |- CUR) node [pos=0.5,anchor=south,rotate=90]{17};
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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