Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following problem with tikz: I want to draw some circular arcs, but unfortunately these arcs have degrees which pass the 360° line. I would like to be able to draw these arcs with one single command, but I can't figure out how to do it. If I give the arc commands two angles where the first is larger than the second, tikz will simply interchange the angles before drawing them.

% radius, two angles, node attribute/name
\newcommand{\drawarc}[5]
{
\draw[gray, very thin] (0,0) --  (#2:#1);
\draw (#2:#1) arc(#2:#3:#1);
\draw[gray, very thin] (0,0) --  (#3:#1);
\draw({(#2+#3)/2}:#1) node[#4] {#5};
}

\begin{tikzpicture}[scale=4]

\drawarc{1cm}{80}{100}{above}{1};

\drawarc{0.9cm}{60}{110}{below}{2};

\drawarc{0.75cm}{20}{85}{below left}{4};

\drawarc{0.8cm}{95}{150}{below right}{3};

\drawarc{1cm}{105}{200}{above}{5};

% I would like to replace these 2 commands
% by one, drawing an arc from 195 to 75 degrees
\drawarc{1.2cm}{195}{360}{above}{6};
\drawarc{1.2cm}{0}{75}{}{};

\drawarc{1.3cm}{160}{280}{left}{8};

\drawarc{0.9cm}{140}{190}{right}{7};

% and the same here
\drawarc{1cm}{260}{360}{above left}{9};
\drawarc{1cm}{0}{40}{}{};
\end{tikzpicture}

I am bounding every arc by lines from/to (0,0), so if I draw multiple arcs where I only need one, the additional lines look somewhat crappy.

share|improve this question

4 Answers 4

up vote 14 down vote accepted

You can use angles greater than 360!

Replace your 4 lines with the following two:

 \drawarc{1.2cm}{195}{435}{above}{6}; 
%\drawarc{1.2cm}{0}{75}{}{}; 360+75=435

and

  \drawarc{1cm}{260}{400}{above left}{9}; 
%\drawarc{1cm}{0}{40}{}{}; 360+40=400

to get the desired result:

enter image description here

share|improve this answer
    
thank you very much, that did the trick –  x2b Jan 25 '12 at 20:33

To do what you want, you can use the delta angle option for an arc. What you have to write is

\draw (195:1.2) arc[radius=1.2,start angle=195,delta angle=240]

If you want to go the other way, use -240 and not 240.

OR

using Yossi's solution, end angle = 435.

share|improve this answer

Damn, away half an hour, and suddenly there are three answers. Anyway, here's mine:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usepackage{ifthen}

\begin{document}

% radius, two angles, node attribute/name
\newcommand{\drawarc}[5]{%
\ifthenelse{#3>#2}%
% if second anvle is bigger, then as usual
           {\draw (#2:#1) arc(#2:#3:#1);
            \draw({(#2+#3)/2}:#1) node[#4] {#5};}%
% otherwise, draw two arcs, and also adapt the node position;
% colors are just for illustration, just remove the [red] and [blue]
           {\draw[red] (#2:#1) arc(#2:360:#1);
            \draw[blue] (360:#1) arc(0:#3:#1);
            \draw({(#2+#3)/2+180}:#1) node[#4] {#5};}%
% connections to arc ends, un changed            
\draw[gray, very thin] (0,0) --  (#2:#1);%
\draw[gray, very thin] (0,0) --  (#3:#1);%

}

\begin{tikzpicture}[scale=2]

% old "solution
\drawarc{1.2cm}{195}{360}{above}{6};
\drawarc{1.2cm}{0}{75}{right}{7};

% new example
\drawarc{1.7cm}{195}{75}{below}{8};

% free bonus pacman!
\drawarc{2.7cm}{225}{135}{right}{Waka Waka!};

\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer

Instead of defining your command in that way I would do the following. Not only will it automatically do it the right way, from your defined angles, but it will also make the middle connection more pretty.

\newcommand{\drawarc}[5]{
    \ifnum#3<#2
      \draw (#2:#1) arc(#2:360:#1) arc(0:#3:#1);
      \node[#4] at ({(#2+360+#3)/2}:#1) {#5};
    \else
      \draw (#2:#1) arc(#2:#3:#1);
      \node[#4] at ({(#2+#3)/2}:#1) {#5};
    \fi
    \draw[gray, very thin,rounded corners=.1pt] (#3:#1) -- (0,0) --  (#2:#1);
}

I have changed the way you place your node. This is more clean, at least I think. Further notice the rounded corners which makes the center piece look much better.

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.