设计机械轴

设计机械轴

有没有更实用的方法可以使用长度和宽度来绘制图形,这样我就不需要像以前那样设置所有的顶点了?

\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}

在此处输入图片描述

答案1

您可以更好地利用coordinatecalc。这里我没有任何绝对坐标来绘制轴:

\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}

可以使用相同的坐标来绘制测量值。这变得有点复杂,但使用从水平方向和垂直方向(Coor1 -| Coor2)获取坐标是可行的。Coor1Coor2

\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}

在此处输入图片描述

相关内容