0

If a node is defined as a circle and you want to use anchors (west and east) from the node to draw an arc around the node, how do you ensure that the arc is anchored about the centre (red line in figure below; see 'using coordinates' in the MWE below) of the circumference of the circle, rather than at the left edge (blue line in figure below; see 'using anchors' in the MWE below).

That is, if you use anchors, the black output is produced, but if you use coordinates, the red output is produced.

I appreciate that this is a subtle point, but I would like to properly understand how node anchors work!

Why not do it simply in terms of coordinates? This is part of a much larger figure where I would ideally like to define drawings in terms of node anchors for simplicity.

Output: enter image description here

MWE:

\documentclass[12pt,tikz]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    %The node:
    \node[circle,draw=black, fill = white, inner sep=0pt,minimum size=1.5cm] (pulley) at (0,0) {};

    %Using anchors:
    \draw[thick,blue] (pulley.west) arc (180:0:0.75);

    %Using coordinates (ideally it should like this output):
    \draw[thick,red] (-0.75,0) arc (180:0:0.75);

    \end{tikzpicture}
\end{document}
1

1 Answer 1

3

I don't know if this was obvious, but here is an example with wider lines to make it easier to see:

output of code

\documentclass[12pt,tikz,border=5mm]{standalone}
\usepackage{tikz}    
\begin{document}
\begin{tikzpicture}
    %The node:
    \node[circle,draw=black, fill = white,line width=1mm, inner sep=0pt,minimum size=1.5cm] (pulley) at (0,0) {};

    %Using anchors:
    \draw[line width=3mm,blue,opacity=0.4] (pulley.west) ++(0.5mm,0) arc[start angle=180,end angle=0,radius=0.75cm];

\node [circle,fill=red,inner sep=0.5pt,draw=none,pin=240:\texttt{.west}] at (pulley.west) {};

\end{tikzpicture}
\end{document}

The clue is that the west anchor lies on the outside of the line, not the middle of it. Because of that you have to shift the start point of the arc by half the width of the line.

(If the width of the node border is the same as the line width used in the \draw, you can use 0.5\pgflinewidth instead of the explicit 0.5mm used above.)

While I used Cartesian coordinates for the shift here, in general it would be better to use polar coordinates (assuming circles). That is, use ++(<start angle>-180:<half the linewidth>) (in this case (0:0.5mm)).

1
  • Fantastic. Great answer. Oct 21, 2017 at 0:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .