2

I have code that instructs TikZ to draw concentric circles with center O. I also draw arcs on these circles measuring 80 degrees. With the command \node (O) at ($(O) + (-90:10pt)$) {$O$};, the center of the circle is shifted; I think that the label O is put at the center of the two circles. Why does this happen? I just want to have O put 10pt below the origin.

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles}

\begin{document}

\begin{tikzpicture}

\coordinate (O) at (0,0);
\draw[fill] (O) circle (1.5pt);
%\node (O) at ($(O) + (-90:10pt)$) {$O$};

\coordinate (A) at ($(O) + (80:1)$);
\coordinate (B) at ($(O) + (80:2)$);

\draw (O) -- (B);
\draw (O) -- ($(O) + (0:2)$);

\draw (O) circle (1);
\draw (O) circle (2);

\draw[line width=1.6pt] (1,0) arc (0:80:1);
\node (angle-label) at ($(O)+(40:10pt)$) {$\scriptstyle{80}$};

\end{tikzpicture}

\end{document}
user74973
  • 4,071
  • 2
    Name O is already used. So change the node name (or get rid of it as you don't seem to use it). \node (O) at ($(O) + (-90:10pt)$) {$O$}; becomes \node (otherNodeName) at ($(O) + (-90:10pt)$) {$O$}; or \node at ($(O) + (-90:10pt)$) {$O$}; – Maarten Dhondt Jun 02 '15 at 13:42
  • @Maarten Dhondt I understand what you are saying. I am changing the location of the origin with \node (O) at ($(O) + (-90:10pt)$) {$O$};. I removed the (O). Thanks. – user74973 Jun 02 '15 at 13:49

1 Answers1

2

@Maarten already answered your question about why things go awry. The node names are references to coordinates. When you name something with an existing name you basically change the coordinate it refers to.

Here when uncommented the rest of your code uses the new location of (O). However I took the liberty to restructure the code and I would like to advocate against the use of calc as such. Because there are simpler ways namely:

  • Drawing from one point to another with known difference

    \draw (3,4) -- ++(-1,1); % <-- Draws to (2,5)
    \draw (1,1) -- ++(45:{sqrt(2)}); % <-- draws to (2,2)
    

    You can find more details in the manual or super briefly in How can I add offsets to coordinates in tikz?

  • Drawing by adding shifts

    \draw (0,0) -- ([xshift=1cm]0,0); % <-- draws to (1,0)
    \draw (1,1) -- ([yshift=1cm]0,2); % <-- draws to (0,3)
    

    You can combine both shifts and give any valid coordinate expression, but because the argument has a parenthesis and a comma we need to protect it via braces

    \draw (0,0) -- ([shift={(90:1cm)}]1,1); %<-- draws to (1,2)
    

You can also combine the relative positioning and shifts but first the coordinate is parsed then the shifts are added

\draw (1,1) -- ++([yshift=-2cm]45:{sqrt(2)}); % <-- draws to (2,0)

Hence using these syntax, your code can be simplified to

\documentclass[tikz]{standalone}
\usetikzlibrary{angles,quotes}
\begin{document}

\begin{tikzpicture}
\coordinate[
    label={[circle,fill,inner sep=1pt]center:{}},
    label=-90:{$O$}] (O) at (0,0) {};
\draw (O) circle (2) (80:2) -- (O) circle (1) -- (0:2) ;
\coordinate (a) at (1,0) ;
\coordinate (b) at (80:1);

\pic[draw,line width=1.6pt,angle radius=1cm,"$\scriptstyle80$"] {angle = a--O--b};
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807
  • Nice explanations. You say that \draw (0,0) -- ([xshift=1cm]0,0); is a command to draw a line (with line width 0.4pt) from the origin to the point (1,0). Do you need to specify a unit for the distance of the xshift? Would TikZ compile the command \draw (0,0) -- ([xshift=1]0,0); and render the same drawing? – user74973 Jun 02 '15 at 19:40
  • Where in the manual is declaring a point by putting command like [xshift=<distance>,yshift=<distance>] before the coordinates a,b of a point, without parentheses, discussed? – user74973 Jun 02 '15 at 19:40
  • @user74973 The xshift argument is understood as 1pt if no unit is provided. The options are given on page 360 of the manual of version 3. If you need to skip the units then you can use shift and use a dimensionless coordinate. – percusse Jun 02 '15 at 19:44