Howto:Build graduate dials with LaTeX: Difference between revisions

Jump to navigation Jump to search
Line 206: Line 206:
\begin{tikzpicture}
\begin{tikzpicture}
...
...
  \draw[draw=cyan, line width=\graduateThick cm] (130:\arcRadius) arc (130:130+60:\arcRadius);
\coordinate (c1) at (0,0);
\draw[fill=yellow, draw=none]
% radius=\arcRadius, initial=270, final=300
($(c1) + (270:\arcRadius-\graduateInternaThick)$)
arc (270:300:\arcRadius-\graduateInternaThick) --
($(c1) + (300:\arcRadius)$)
arc (300:270:\arcRadius) -- cycle;
\draw[fill=red, draw=none]
% radius=\arcRadius, initial=45, final=270
($(c1) + (45:\arcRadius-\graduateThick)$) arc (45:270:\arcRadius-\graduateThick) --
($(c1) + (270:\arcRadius)$) arc (270:45:\arcRadius) -- cycle;
...
...
\end{tikzpicture}
\end{tikzpicture}
</syntaxhighlight>
</syntaxhighlight>
The command is fairly clear and the parameters to be varied also, the thickness is defined by a value inserted in the ''\graduateThick'' (within the square brackets) variable, which is also the thickness of the outer diameter ring. Obviously it can be redefined with a numeric value. It is important to note the presence of the measurement "cm" unit so that for the thickness of the ring do not use a different measurement units <ref>Units permitted by LaTeX: https://tex.stackexchange.com/questions/8260/what-are-the-various-units-ex-em-in-pt-bp-dd-pc-expressed-in-mm</ref>, as for example the typographical point ( pt = 1/72 inches).<BR>[[File:LaTeX Coordinates System.jpg|thumb|LaTeX Coordinates System<ref>Graphics with TikZ (''Andrew Mertz and William Slough'') Pag. 12 : https://www.tug.org/pracjourn/2007-1/mertz/mertz.pdf</ref>|right|400px]]The definition of the arc requires some attention as the center of rotation needs to be defined, if it were placed (0,0) the center would coincide with the center of the Cartesian axes (Latex uses Cartesian notation, that is, the angles are anti-clockwise and the angle zero corresponds to the horizontal axis of the X)<ref>Example of coordinates in the LaTeX: https://tex.stackexchange.com/questions/155181/coordinate-system-in-latex-with-tikz</ref>.A purely Cartesian reference system requires some attention for those who commonly use the reference system used for CAD or other graphical programs (lower Y, clockwise angles). Therefore the command:<BR>
The method is to draw two arcs and two straight lines connecting them to the edges and then fill the whole with a color. The reason is that in TiKz there is no function to draw a bow directly, of course it is possible to realize it, but it is not said that in such simple cases it is useful. Therefore it is using TikZ like a plotter that traces the edge of the figure we want to achieve, in this way it is possible to make special effects such as arc segments which reduce or increase their thickness, as we shall see in another example later.<BR>The parameter '''c1''' defines the arc center that uses the ''\coordinate'' function, which is needed to have a center of arc independent of the starting point, in fact defining the center of a circle is simple, but an open figure like an arc is much less! Therefore, the calculation '''$''' ''(c1) + (270: \arcRadius-\graduateInternaThick)'' '''$''' is used to compute the center of the arc having coordinates (0,0).
'''...(130:\arcRadius) arc (130:130+60:\arcRadius)...'''<BR>
<syntaxhighlight lang="latex">
so read:<BR>
\coordinate (c1) at (0,0);
'''130: \arcRadius''' : It is the beginning point of the arc that starts from the axis of the X and performs an angle of 130° counterclockwise, positioning at the 340 ° of the graduate dials, the ''\arcRadius'' parameter is the arc radius.<BR>
</syntaxhighlight>
'''arc''' : This is the keyword of the arc function.<BR>
The second part ''arc (270:300:\arcRadius-\graduateInternaThick)'' draws an arc starting at 270 ° and ending at 300 °, remembering that in the Cartesian reference system the angle 0 ° corresponds to the horizontal axis of X and the rotation is anti-clockwise.
'''(130:130+60:\arcRadius)''' : The first value is the initial angle, in our example 130° obtained as angular distance from the X axis measured counterclockwise. The second angle is 130° + the arc angle (in our example is 60 °) that give the value 190° (corresponding to 260 ° of the graduate dials), the third parameter is the arc radius defined by ''/arcRadius'' parameter. So if you want to get any arc, just change the three parameters. It may seem complicated because it has a very different method from the usual one, but it allows you to get any type of arc in any position.
As is evident the radius of this arc is defined by this expression: ''\arcRadius-\graduateInternaThick''<BR>
The "'''--'''" indicates that you draw a line beginning at the end of the arc and arrives at the beginning of the next arc that this time will proceed in the opposite direction, and then close the figure.<BR>The expression ''($(c1) + (300:\arcRadius)$)''  define a new center where finish the line and restar the return arc as describe by this expression: ''arc (300:270:\arcRadius)'', it is important to note that now the system draws the arc in the opposite direction, ie from 300 ° to 270 ° with a different radius defined by the variable: ''\arcRadius''. Finally, you must enter the closing line: "'''--'''".<BR>Once the shape to be drawn is defined, we can color it with the color (''fill=color'' parameter) and define the edge ('draw = ...''), if the edge parameter is assigned ''none'' the edge will not be drawn.
 
====A note about units of measurement====
When a numeric value is expressed in our format, it is assumed that it is in "cm", but it can be prefigured in a different unit of measurement, for example "mm", just place the relative unit at its numeric value of measure adopted. For instance, you can write 1 to indicate ''1'' cm or the equivalent value in mm: ''10mm''<ref>Units permitted by LaTeX: https://tex.stackexchange.com/questions/8260/what-are-the-various-units-ex-em-in-pt-bp-dd-pc-expressed-in-mm</ref>, as for example the typographical point ( pt = 1/72 inches).
 
====A note about the coordinate system adopted in LaTeX:====
[[File:LaTeX Coordinates System.jpg|thumb|LaTeX Coordinates System<ref>Graphics with TikZ (''Andrew Mertz and William Slough'') Pag. 12 : https://www.tug.org/pracjourn/2007-1/mertz/mertz.pdf</ref>|right|400px]]
The definition of the arc requires some attention as the center of rotation needs to be defined, if it were placed (0,0) the center would coincide with the center of the Cartesian axes (Latex uses Cartesian notation, that is, the angles are anti-clockwise and the angle zero corresponds to the horizontal axis of the X)<ref>Example of coordinates in the LaTeX: https://tex.stackexchange.com/questions/155181/coordinate-system-in-latex-with-tikz</ref>.A purely Cartesian reference system requires some attention for those who commonly use the reference system used for CAD or other graphical programs (lower Y, clockwise angles). Defines the starting point to begin drawing the arc, the point is localized starting from the center in Cartesian coordinates ''(<X>,<Y>)'' and moving from this point to a new point defined this time with polar coordinates ''(<angle>: <radius>)'', as can be seen from the command executed to assign the first arc point:
''...(c1) + (270:\arcRadius-\graduateInternaThick)...''<BR>
The power and flexibility of TiKz language can sometimes be baffled, but it is the intrinsic force of a powerful and extremely synthetic language. It is clearly possible to mix different types of references (Cartesians and Poles), different units of measurement, and perform algebraic, trigonometric calculations and many other types of functions on them. Often TiKz is used along with another powerful language for GNUPLOT<ref>An example for GNUPLOT basics integration is show in this article: http://www.texample.net/tikz/examples/gnuplot-basics/</ref> statistical graphics, which completely integrates with TiKz and then LaTeX.


===The complete code===
===The complete code===
412

edits

Navigation menu