2

I want to draw an arc of a certain length in cm, so I divide by the circumference in cm and multiply 360 to get the segment in degrees. (Is there a shortcut?)
In my MWE b is the unitless number I want to get from a.

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}

    \def\a{3.14cm}
    \node[scale=0.5] at (-1,0) {\a};

    \def\b{{\a / (1cm*pi) *20}}
    \def\c{20}

    \node[scale=0.5] at (-1,1) {\b};

    \draw[very thin] (0,0) -- (\a/3,0);
    \draw[very thin] (0,0.1) -- (\b,0.1);
    %\draw[very thin] (0,0.1) -- ({\b+0.1},0.1);

    \draw[red] (1:1) arc (1:1+20:1);
    \draw[blue] (30:1) arc (30:{(30+\c)}:1);
    %\draw[green] (60:1) arc (60:{(60+\b)}:1);

\end{tikzpicture}
\end{document}

As can be seen from the node text and the commented lines b does not behave like a unitless scalar. Removing either comment yields ERROR: Missing number, treated as zero.
How can I make b unitless? enter image description here

  • Do you also want to draw the radius with the circumference? Why don't you use sin(x) and cos(x) as \draw [red,thick,domain=0:90] plot ({cos(\x)}, {sin(\x)});? – Sina Ahmadi Feb 22 '19 at 12:41
2

\pgfmathsetmacro removes units. (I replaced 20 by 2 because the plot was huge when using 20.)

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}

    \def\a{3.14cm}
    \node[scale=0.5] at (-1,0) {\a};

    \pgfmathsetmacro\b{{\a / (1cm*pi) *2}}
    \def\c{20}

    \node[scale=0.5] at (-1,1) {\b};

    \draw[very thin] (0,0) -- (\a/3,0);
    \draw[very thin] (0,0.1) -- (\b,0.1);
    \draw[very thin] (0,0.1) -- (\b+0.1,0.1);

    \draw[red] (1:1) arc (1:1+20:1);
    \draw[blue] (30:1) arc (30:{(30+\c)}:1);
    \draw[green] (60:1) arc (60:{(60+\b)}:1);

\end{tikzpicture}
\end{document}

enter image description here

|improve this answer|||||

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.