29

I'm trying to fix the following TikZ figure, where the circle device in the middle should be embraced by two bended arrows pointing counter-clockwise.

figure with broken orientation for arrows

I have drawn these arrows with an arc path, but the tips of the arrows are unexpectedly both pointing upward. Any idea how to get these arrow tips to follow the direction of the arc?

Here is my code for the above figure:

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}

 \draw (0,0) circle (1cm);

 \draw[fill=gray!20]  (23:0.45cm)
    -- (23:1cm) arc[radius=1, start angle=23, end angle=-203] (157:1cm)
    -- (157:0.45cm) arc[radius=0.45, start angle=157, end angle=23] (23:0.45cm);

 \draw[fill] (0,0) circle(2pt);

 \draw[->,>=stealth',semithick] (150:1.2cm) arc[radius=1.2, start angle=150, end angle=210] (210:1.2cm);
 \draw[->,>=stealth',semithick] (-30:1.2cm) arc[radius=1.2, start angle=-30, end angle=30] (30:1.2cm);

 \foreach \x/\y in {1/0,2/0,3/0,4/1,5/1,6/1,7/0,0/1}
    \node[rotate={\x*45-90}] at ($(0,0)!.75!\x*45:(1,0)$) {\y} ;
\end{tikzpicture}
\end{document}

3 Answers 3

37

That is due to the fact that you are adding the final coordinate. They should not be there. Simply change the lines to:

\draw[->,>=stealth',semithick] (150:1.2cm) arc[radius=1.2, start angle=150, end angle=210];
\draw[->,>=stealth',semithick] (-30:1.2cm) arc[radius=1.2, start angle=-30, end angle=30];

This problem arises in far simpler situations as well, it is not inherent to the curve. Consider for example \draw[->] (0,0) -- (2,0) (2,0); which will give an upward pointing arrow on the end of a horizontal line. Basically the new coordinate begins a new path segment and only the last segment of the path is given the arrowtip.

0
8

The problem arises due to the path direction not being explicitly calculated with the curve when you use the arc[radius=1, start angle=23, end angle=-203] (150:210:1.2cm) notation. This is due to the reasoning given by wh1t3, instead use the shorter, and which gives you the correct path and arrow:

\draw[->,>=stealth',semithick] (150:1.2cm) arc (150:210:1.2cm);
\draw[->,>=stealth',semithick] (-30:1.2cm) arc (-30:30:1.2cm);
5
  • 2
    This does solve the problem. For the same reason as my solution does. It does not have the final coordinate. I don't know what you mean when you say "the path not being explicitly calculated with the curve", could you elaborate on that? Dec 12, 2011 at 15:18
  • 2
    Actually the TikZ manual seems to recommend against this shorter syntax. It says "There also exists a shorter syntax for the arc operation [...] However, this syntax is harder to read, so the normal syntax should be preferred instead." (Yet the manual is full of examples with the shorter syntax.)
    – adl
    Dec 12, 2011 at 15:20
  • @wh1t3 it was due to your reasoning that the final path direction was not calculated, sorry for the misunderstanding in the question at hand, i have corrected the answer
    – nickpapior
    Dec 12, 2011 at 21:58
  • @adl yes, however it is a matter of what is the easiest for yourself to do. The single argument against is is harder to read. However I find it pretty self-explanatory. Maybe because i have gotten used to it. I do not know. But you should not do what i said, just because i said it. Do what you feel most comfortable doing! :)
    – nickpapior
    Dec 14, 2011 at 21:03
  • This does not solve the problem... see tex.stackexchange.com/questions/600109/…
    – Jason S
    Jun 5, 2021 at 21:03
4

I agree with wh1t3, the problem comes from the path. The path in gray is also delimited in a strange way. It's not a problem of syntax, the syntax radius=..., start angle=..., end angle=... is fine but the shorter syntax is often (always) preferred. The other syntax uses arc [...] like edge[...] and it is tempting to follow the brackets by a node (...).

Here a code more concise but it is not because a code is more concise than another it is always best. And your case, you can avoid \x/\y.

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}

\begin{document}
\begin{tikzpicture}
  \draw[fill=gray!20](23:0.45cm) arc (23:157:0.45cm) -- (157:1cm) arc(157:383:1cm)--cycle ;
  \draw[->,>=stealth',semithick] (150:1.2cm) arc (150:210:1.2cm);
  \draw[->,>=stealth',semithick] (-30:1.2cm) arc (-30:30:1.2cm);    
  \foreach \y[count=\x from -1] in {0,0,0,1,1,1,0,1} 
       \node[rotate={\x*45}] at (45*\x+90:0.75cm) {\y} ;
  \draw[fill] (0,0) circle(2pt);  
  \draw (0,0) circle (1cm);  
\end{tikzpicture}
\end{document}
4
  • 1
    You disagree with the TikZ manual on which form is preferred, but your logic is convincing. The arc operation is confusing because it starts at the current point but is centered at a point that is only implicitly specified by the parameters, and ends at an implicit point as well, so that after using it, the current point was never actually written anywhere. With the short form, at least if you are arcing around the center of coordinates, the second parenthetical group does tell you the coordinates of the end point.
    – Ryan Reich
    Dec 12, 2011 at 19:08
  • I disagree ... I'm not sure; T.Tantau in the first tutorial uses arc (0:30:3mm);. The new syntax is recent and I use from long time the old syntax. Tantau uses the new syntax only in the index :) Dec 12, 2011 at 19:30
  • I guess I'd prefer a syntax something like (p) arc [center = c] (q), or if you want to give the angle, (p) arc [start angle = a, end angle = b] (q) (the center can be inferred from this). Or even just the radius: (p) arc [radius = r, (swap?)] (q), since knowing the radius there are only two positions for the center, and therefore the arc would go either "left" of the straight line or "right" of it, just like a node placed with auto. I do agree with Tantau that the keywords are more expressive than the short form.
    – Ryan Reich
    Dec 12, 2011 at 19:50
  • Thank you for the count= trick. I didn't know about this syntax.
    – adl
    Dec 12, 2011 at 21:33

You must log in to answer this question.

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