1

I am new to plotting in TikZ and has come across the "Missing number error" in the following example on the line marked by %(**),

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.geometric,arrows,intersections} 
%shapes.geometric and arrows are used in other TikZ graphics not included in this MCVE
\begin{document}
\begin{tikzpicture}[scale=0.3]
\draw [name path=yaxis, ->,thick] (0,-2)--(0,12) node (yax) [above] {$\Im E$};
\draw [->,thick] (-20,0)--(12,0) node (xax) [right] {$\Re E$};
\path [name path=circular] (-15,0) arc (180:0:8);
\path [name intersections={of=circular and yaxis}];
\coordinate (c) at (intersection-1);
\draw [->,thick] let
    \p1=(c),
    \n1={\y1/8},              %(*)
    \n2={asin(\n1)}           %(**)
in (-15,0) arc (180:\n2:8);   %(***)
\draw let \p1=(c) in (0,\y1)--(7,\y1);
\end{tikzpicture}
\end{document}

I have checked the existing questions on this site but has not yet found an answer, I tried adding braces in various ways around %(*) and %(**), with no success. I also tried to merge the two lets into one like \n1={asin(\y1/8)}, and tried variations of this with braces added. All of them report missing numbers error. If I replace \n1in line %(**) with a number, or use \n1 in place of \n2 in %(***) (Not what I intended but I just want to check) there is also no errors.

Other observations,

  • If I replace acos with ln, no error is reported
  • If I replace \y1/8 with \y1, the error "Dimension too large" is reported

Edit

asin(\y1/8)=acos(7/8), so I can plot what I want anyway, but I just don't understand where the error comes from.

  • The error is due to the fact that you ask TikZ to take the arcsin of a number that is larger than 1. (There is an unrelated error in \draw [name path=yaxis, ->,thick] (0,-2)--(0,12) node (yax) [above] {$\I, which you seem to have forgotten to complete). – marmot Apr 11 at 16:24
  • Fixed the $\I$ part, I tried changing \y1/8 to \y1/80 and got the same error, so I didn't think that was the reason. However, after you commented I double checked and now I believe you are correct. – Weijun Zhou Apr 11 at 17:48
  • (There is still a semicolon missing.) You can condense the relevant two lines to \draw [->,thick] let \p1=(c) in (-15,0) arc (180:{asin(\y1/8cm)}:8); \draw (c-|0,0) -- (c-|7,0);. – marmot Apr 11 at 17:54
  • Thank you for your advice. I will take it. – Weijun Zhou Apr 11 at 17:56
1

I personally would compute the angle in a different way (assuming you do not want to do it analytically). You have a semicircle around (-7,0) of radius 8cm, of which you want to draw the path to the intersection of the y-axis. That is, we want the polar coordinates of (c)-(-7,0). The angle can be computed via atan2, which avoids having to divide by dimensions, and related errors that may occur when asking TikZ to compute the arcsin of a number larger than 1, as it occurs. atan2 is defined for any arguments, so this error cannot occur (and this way of computing the angle is arguably more intuitive). The horizontal stretch does not require calc (but of course there is nothing wrong with using calc here).

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{calc,intersections} 
\begin{document}
\begin{tikzpicture}[scale=0.3]
\draw [name path=yaxis, ->,thick] (0,-2)--(0,12) node (yax) [above] {$\Im E$};
\draw [->,thick] (-20,0)--(12,0) node (xax) [right] {$\Re E$};
\path [name path=circular] (-15,0) arc (180:0:8);
\path [name intersections={of=circular and yaxis}];
\coordinate (c) at (intersection-1);
\draw [->,thick] let  \p1=($(c)-(-7,0)$),
    \n1={atan2(\y1,\x1)} in (-15,0) arc (180:\n1:8);  
\draw (c-|0,0) --  (c-|7,0);
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    Tried atan2 before I got the cm part. I had a number (without dimension) at where you put \x1 and the result was not as expected. I guess I need to know about the cm before I can write correct code as above. Anyway, in the final version I used acos(7/8) and removed all the lets altogether. – Weijun Zhou Apr 11 at 18:10
1

I found the answer in a closed question. To me that question is very clear what is being asked and I don't know why it was closed.

Following the 2nd comment in Tikz: Translate between pt and unit measurements, I changed \n1={\y1/8} to \n1={\y1/8cm}, and it worked as expected. This is because the internal coordinate system uses cm as the unit length but reports coordinates with unit pt when using the coordinate assignment.

Still, I don't understand why the error is "Missing number, treated as zero", but at least I know what is the correct thing to do in the future.

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.