4

I tried to paint a protractor. But am not able to paint some kind of separators along the arc. Especially the smaler radius seems to be a problem for me :(

Here's a MWE:

\documentclass{scrartcl}
\usepackage[english]{babel}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture} 
\draw[color=black] (1,1)--(5,1)--(5,1.5)--(4.5,1.5) arc[radius = 1.5, start angle = 0, end angle = 180]--(1,1.5)--(1,1);
\draw (4,1.5) arc[radius = 1, start angle = 0, end angle = 180]--(4,1.5);

\foreach \angle in {0, 30, 60, 90, 120, 150, 180}  {
\draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
}
\end{tikzpicture}

\end{document}

How can I change the position of the scale, up to the arc and change the size of the separator-arc?

the final picture should look like this:

enter image description here

  • Centre the protractor so the base of the arc is at (0,0) or use a shift when adding the angles. Use something like 1.3cm and 1.5cm rather than 1.8cm and 2cm if your largest arc is 1.5cm. Or make the largest arc 2cm. – cfr Dec 11 '16 at 15:07
  • A nice protractor with tikz from @Ignasi: tex.stackexchange.com/a/283150/31034 – ferahfeza Dec 11 '16 at 16:23
6

enter code here

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}

\begin{tikzpicture}
\draw[color=black] (1,1)--(5,1)--(5,1.5)--(4.5,1.5) arc[radius = 1.5, start angle = 0, end angle = 180]--(1,1.5)--(1,1);
    \draw (4,1.5) arc[radius = 1, start angle = 0, end angle = 180]--(4,1.5);

\foreach \angle in {0, 30, 60, 90, 120, 150, 180}  {
\draw[red,line width=1pt] (3,1.5) ++ (\angle:1.3cm) -- ++  (\angle:0.2);% <-- changed
}
\end{tikzpicture}

\end{document}

At polar coordinates, if you not define starting point, starts from coordinate (0,0). Therefore in above solution the starting point is shifted by (3,1.5) ++ (\angle:1.3cm) and also used relative positioning with -- '' (-- ++ (\angle:0.2);.

Another possible solution is redraw protractor so that starting point is at begin of arc instead of its below left corner: see answer of @cfr.

Off-topic: in drawing of arc you can use shorter notation: (<start angle>:<end angle>:<radious>), for example:

\draw   (1.5,0) arc (0:180:1.5) -| ++ (-0.5,-0.5) -| ++ (4,0.5) -- cycle;
\draw   (1.0,0) arc (0:180:1) -- cycle;

(where is assumed, that drawing of "separators" is done by:

\foreach \angle in {0, 30, 60, 90, 120, 150, 180}  
{
\draw   (\angle:1.3cm) -- ++  (\angle:0.2);
}

Addendum: for fun:

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
    \begin{tikzpicture}
\draw   (1.5,0) arc (0:180:1.5) -| ++ (-0.5,-0.5) -| ++ (4,0.5) -- cycle;
\draw   (1.0,0) arc (0:180:1) -- cycle;

\foreach \angle in {0, 30,...,180}  
{
\draw   (\angle:1.25) node[font=\tiny,sloped,rotate=-90+\angle] {\angle} 
                     ++ (\angle:0.1) -- ++  (\angle:0.15);
}
\foreach \angle in {0, 10,...,180}
{
\draw   (\angle:1.4) -- ++  (\angle:0.1);
}

\draw (0,0) -- ++ (0,-0.1);
\end{tikzpicture}
\end{document}

which gives:

enter image description here

  • Wow thanks. Thats exactly what i wanted :) But what stands the notation -| ++ for? Is this a short notation for a vertical/horizontal line? – dokukaefer Dec 11 '16 at 22:08
  • yes. it roughly said, means "draw line horizontally and than vertically relative to previous coordinate for amount given in coordinate which follows". – Zarko Dec 11 '16 at 22:44
4

If you centre the base of the arcs on (0,0), then adding the marks etc. is easier. For example:

\documentclass[tikz,border=10pt,10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (1.5,0) arc[radius = 1.5, start angle = 0, end angle = 180] -| ++(-.5,-.5) -| ++(4,.5) --cycle;
\draw (1,0) arc[radius = 1, start angle = 0, end angle = 180] -- cycle;

\foreach \angle in {0, 30, 60, 90, 120, 150, 180}  {
\draw [line width=1pt] (\angle:1.3cm) -- (\angle:1.5cm);
}
\end{tikzpicture}
\end{document}

protractor

  • ups, my second example (added later) is almost the same as your example. I will erase it ... – Zarko Dec 11 '16 at 15:32
4

By default, polar coordinates start drawing centered at (0,0), so, you need to shift the separators by (3cm,1.5cm) to move to the new center. This is easily achieved in a scope.

\documentclass{scrartcl}
\usepackage[english]{babel}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture} 
\draw[color=black] (1,1)--(5,1)--(5,1.5)--(4.5,1.5)coordinate(o) arc[radius = 1.5, start angle = 0, end angle = 180]--(1,1.5)--(1,1);
\draw (4,1.5) arc[radius = 1, start angle = 0, end angle = 180]--(4,1.5);

\begin{scope}[shift={(3cm,1.5cm)}]
\foreach \angle in {0, 30, 60, 90, 120, 150, 180}
  \draw[line width=1pt] (\angle:1.5cm) -- (\angle:1.3cm);
\end{scope}

\end{tikzpicture}

\end{document}

enter image description here

3

Just for comparison with the Tikz solutions, here's one I did earlier in Metapost + luamplib. Compile with lualatex.

enter image description here

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\usepackage{fontspec}
\setmainfont{TeX Gyre Heros}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    color plastic; plastic = 1/256(215,205,190);

    path lower_base, upper_base, inner_arc, outer_arc;

    upper_base = (left--right) scaled 5.2 cm;
    lower_base = upper_base shifted (0,-1.6cm);
    inner_arc = halfcircle scaled 5.4cm;
    outer_arc = halfcircle scaled 8.8cm;

    % make the plastic body
    fill lower_base -- point 1 of upper_base -- outer_arc -- point 0 of upper_base -- cycle withcolor plastic;
    unfill inner_arc -- cycle;

    % draw the scale along the base
    for t = 0 upto 100:
       x := 50-t;
       draw (origin -- if x mod 10 = 0: 8 elseif x mod 5 = 0: 6 else: 5 fi up) shifted (x*mm, ypart point 0 of lower_base);
       if x mod 10 = 0:
         label.top(decimal (t/10) infont defaultfont scaled 0.7
         rotated 180, (x*mm,ypart point 0 of lower_base + 9)); 
       fi
    endfor

    % and the scale around the arc
    for t = 0 upto 180:
       draw (origin -- if t mod 10=0: 16 elseif t mod 5=0: 12 else: 8 fi left)
            shifted point 0 of outer_arc rotated t;
       if t mod 10=0:
          if t=90:
              label("90" infont defaultfont scaled 1.4, 26 down shifted point 2 of outer_arc);
          else:
              label(decimal       t infont defaultfont scaled 0.7 rotated (t-90), 22 left shifted point 0 of outer_arc rotated t);
              label(decimal (180-t) infont defaultfont scaled 0.7 rotated (t-90), 30 left shifted point 0 of outer_arc rotated t)
              withcolor .78 red;
          fi
       fi
    endfor

    % finally mark the middle
    draw origin -- 4 down;
    unfill fullcircle scaled 2;

endfig;
\end{mplibcode}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.