3

I am a beginner in LaTeX, tentatively using it for industrial documents. I am having difficulties with drawing arcs in TikZ. In the MWE, I am trying a routine that would draw a series of coding mechanical keys, in order to clarify the coding pattern. (It is based on protrusions that should be aligned with some of the numbers shown) Each key is a hollow cylinder, outer dia \DiaExt, section shown in orange, and there is one or several protrusions, width \KeyWidth, placed at different angles on the outer envelope. (only one is shown tentatively in the MWE by showing the 4 envelope points). Their location is now calculated in the code.The points black and green should be connected by a vertical segment, the points red and blue also. The lower points green and blue are to be connected by an arc diameter \DiaExt. In fact in the final picture, all the points are to be connected and the inner area filled in orange, to make a continuum with the orange area.

My problem is:

  1. how to draw the arcs connecting the upper points black and red, and the lower points blue and green? (Problem solved in the edited code using the proposal from Altermundus)
  2. How to draw the path between the points black, red, blue green automatically, in such a way that several other keys could be made on the same principle.
  3. I have found a way to adjust the size of the engraved numbers to match the reel parts, but not in a way that adjusts if the scale of the picture is modified. Is there a way to make the size of the numbers following the scale of the main picture?
\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}
2

1 Answer 1

5

It's possible to fill the area in the background (layers)

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

enter image description here

3
  • Using the solution proposed, I was able to modify the code of the MWE, and calculate automatically the position of the 4 points. (Correcting a mistake in the hardcoded Y position and making the code more flexible) However I still cannot find a way to draw the vertical lines to connect the ends of arcs, since \draw[very thick] (b) -- (c); does not work as expected, and even less to close the path in order to fill the inner area of the key with a color...
    – Yves
    Commented Jul 3, 2012 at 10:49
  • I update my answer. You can use the layers (main,background) to adapt my answer. Commented Jul 3, 2012 at 11:07
  • Great! Thanks !. I still have the goal of linking the size of the large engraved numbers to the magnification factor, but this is not essential.
    – Yves
    Commented Jul 3, 2012 at 11:12

You must log in to answer this question.

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