如何在 TikZ 中绘制连接两点的圆弧?

如何在 TikZ 中绘制连接两点的圆弧?

我是 LaTeX 的初学者,暂时将其用于工业文档。我在 TikZ 中绘制弧线时遇到了困难。在 MWE 中,我正在尝试一种例程,该例程将绘制一系列编码机械键,以阐明编码模式。 (它基于应与所示的某些数字对齐的突起)每个键都是一个空心圆柱体,外径,截面\DiaExt以橙色显示,并且有一个或多个突起,宽度\KeyWidth,以不同的角度放置在外壳上。 (在 MWE 中仅通过显示 4 个包络点暂时显示一个)。现在已在代码中计算出它们的位置。黑色点和绿色点应通过垂直段连接,红色点和蓝色点也应连接。下方的绿色点和蓝色点要通过圆弧直径连接\DiaExt。事实上,在最终的图片中,所有点都要连接起来,内部区域要填充橙色,以与橙色区域形成连续体。

我的问题是:

  1. 如何绘制连接上方黑色和红色点以及下方蓝色和绿色点的弧线?(使用 Altermundus 的提议在编辑的代码中解决了问题)
  2. 如何自动绘制黑点、红点、蓝点和绿点之间的路径,以便可以按照相同原理制作其他几个键。
  3. 我找到了一种方法来调整雕刻数字的大小以匹配卷轴部分,但这种方法不能在图片比例改变时进行调整。有没有办法让数字的大小与主图片的比例一致?
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{scalefnt}
\usepackage[T1]{fontenc} % Usual fonts
\usepackage{tgheros,textcomp}% Fonts

\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\def\magnif{4} %picture magnification ratio
\def\KeyAngle{0} %Angular position of key

\def\DiaShellMachining{0.925}
\def\DiaExtKey{.76}
\def\DiaExt{0.63}
\def\DiaInt{0.5}
\def\KeyWidth{0.32}

{\scalefont{3.1}
\begin{tikzpicture}[scale=\magnif]

\clip (-1,-1) rectangle (1,1);
\draw  [gray] (0,0) circle (\DiaShellMachining/2);

\draw [](0.31, 0.57) node (one) {1}; % first engraved characters
\draw [](0.09, 0.6) node (two) {2};
\draw [](-0.16, 0.6) node (three) {3};
\draw [](-0.37, 0.55) node (four) {4};
\draw [](-0.31,-0.5) node (five) {5};
\draw [](0.345,-0.5) node (six) {6}; %last engraved character

\draw [very thick, color=gray, rounded corners=10mm] (0.49750,-0.5225) rectangle (2.91,.8225); %Shell
\draw [very thick,  color=gray, rounded corners=10mm] (-0.49750,-0.5225) rectangle (-2.91,.8225); %Shell
\draw [ultra thick, color=gray] (-2, 0.9075) -- (2, 0.9075);%Shell upper limit
\draw [ultra thick, color=gray] (-2, -0.6075) -- (2, -0.6075);%Shell lower limit

\fill[orange,even odd rule] (0,0) circle(\DiaInt/2) circle(\DiaExt/2); %Painted ring at front of key

\begin{scope}[rotate=\KeyAngle]

\pgfmathparse{0.5*\DiaExtKey*cos(asin (\KeyWidth/(\DiaExtKey)))} \let\Youter\pgfmathresult

\pgfmathparse{0.5*\DiaExt*cos(asin (\KeyWidth/(\DiaExt)))} \let\Yinner\pgfmathresult

\draw  [color=black] (-0.5*\KeyWidth, \Youter) node (a) {.};
\draw  [color=red] (0.5*\KeyWidth, \Youter)  node (b) {.};
\draw  [color=blue]  (0.5*\KeyWidth, \Yinner)  node (c) {.};
\draw  [color=green]  (-0.5*\KeyWidth, \Yinner)  node (d) {.};

\pgfmathparse{(\Youter) / (0.5*\KeyWidth)} \let\ThetaOne\pgfmathresult % Y coordinate of upper key corners
\pgfmathparse{(\Yinner) / (0.5*\KeyWidth)} \let\ThetaTwo\pgfmathresult  %Y coordinate of lower key corners
\pgfmathparse{sqrt ((\Youter)^2)+((0.5*\KeyWidth) ^2 )} \let\ra\pgfmathresult 

\draw[very thick] ({atan(\ThetaTwo)}:0.5*\DiaExt) arc ({atan(\ThetaTwo)}:{180-atan(\ThetaTwo)}:0.5*\DiaExt); 

\draw[very thick, orange] ({atan(\ThetaOne)}:\ra) arc ({atan(\ThetaOne)}:{180-atan(\ThetaOne))}:\ra); 
\end{scope}
\end{tikzpicture}
}%
\end{document}

答案1

可以填充背景区域(图层)

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{scalefnt}
\usepackage[T1]{fontenc} % Usual fonts
\usepackage{tgheros,textcomp}% Fonts

\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\def\magnif{4} %picture magnification ratio
\def\KeyAngle{0} %Angular position of key


\def\DiaShellMachining{0.925}
\def\DiaExtKey{.76}
\def\DiaExt{0.63}
\def\DiaInt{0.5}
\def\KeyWidth{0.32}


{\scalefont{3.1}
\begin{tikzpicture}[scale=\magnif]

\clip (-1,-1) rectangle (1,1);
\draw  [gray] (0,0) circle (\DiaShellMachining/2);

\draw [](0.31, 0.57) node (one) {1}; % first engraved characters
\draw [](0.09, 0.6) node (two) {2};
\draw [] (-0.16, 0.6) node (three) {3};
\draw [] (-0.37, 0.55) node (four) {4};
\draw [](-0.31,-0.5) node (five) {5};
\draw [] (0.345,-0.5) node (six) {6}; %last engraved character


\draw [very thick, color=gray, rounded corners=10mm] (0.49750,-0.5225) rectangle (2.91,.8225); %Shell
\draw [very thick,  color=gray, rounded corners=10mm] (-0.49750,-0.5225) rectangle (-2.91,.8225); %Shell
\draw [ultra thick, color=gray] (-2, 0.9075) -- (2, 0.9075);%Shell upper limit
\draw [ultra thick, color=gray] (-2, -0.6075) -- (2, -0.6075);%Shell lower limit

\fill[orange,even odd rule] (0,0) circle(\DiaInt/2) circle(\DiaExt/2); %Painted ring at front of key

\begin{scope}[rotate=\KeyAngle]

\pgfmathparse{0.5*\DiaExtKey*cos(asin (\KeyWidth/(\DiaExtKey)))} \let\Youter\pgfmathresult

\pgfmathparse{0.5*\DiaExt*cos(asin (\KeyWidth/(\DiaExt)))} \let\Yinner\pgfmathresult

\draw  [color=black] (-0.5*\KeyWidth, \Youter) node (a) {.};
\draw  [color=red] (0.5*\KeyWidth, \Youter)  node (b) {.};
\draw  [color=blue]  (0.5*\KeyWidth, \Yinner)  node (c) {.};
\draw  [color=green]  (-0.5*\KeyWidth, \Yinner)  node (d) {.};

\pgfmathparse{(\Youter) / (0.5*\KeyWidth)} \let\ThetaOne\pgfmathresult % Y coordinate of upper key corners
\pgfmathparse{(\Yinner) / (0.5*\KeyWidth)} \let\ThetaTwo\pgfmathresult  %Y coordinate of lower key corners
\pgfmathparse{sqrt ((\Youter)^2)+((0.5*\KeyWidth) ^2 )} \let\ra\pgfmathresult 

\fill[green!50,draw=black,thick] ({atan(\ThetaOne)}:\ra) -- ({atan(\ThetaTwo)}:0.5*\DiaExt) arc ({atan(\ThetaTwo)}:{180-atan(\ThetaTwo)}:0.5*\DiaExt) -- ({180-atan(\ThetaOne))}:\ra) arc ({180-atan(\ThetaOne))}: {atan(\ThetaOne)}:\ra) ; 

\end{scope}
\end{tikzpicture}
}%
\end{document}

在此处输入图片描述

相关内容