6

If I want to draw a something with circular symmetry, e.g joining pair of points by arcs as shown in the picture with only two, I face the problem of not being able to use the edge bending. This is because it implies the choice of bend left (or right, or...) which breaks the symmetry.

I want to bend my edges to the center of the circle, but the arcs bend too much towards the center (arc in blue). I can correct, e.g. by adding a coordinate (arc in red). Isn't there an option to tell controls .. not to bend that much?

At the bottom there is another picture which shows what I don't want (and happens if I use bend left). I want in all arcs to be pulled to the center. I cannot fix by reordering a big list manually in finite time.

enter image description here

\documentclass{standalone} 
\usepackage{tikz}

\usepackage{ifthen}


\usepackage{pgfplots} 
\usetikzlibrary{calc}

\begin{document}


\begin{tikzpicture}[scale=1]


\coordinate (O) at (0,0);
\draw (O)  circle (4);
%  
 \foreach \i in {1,2,...,8} {

 \node[draw,fill=white,circle] (p\i) at ($(O)+(360*\i/8:4)$)  {\i};
   }

\draw [blue] (p1) .. controls (O) ..  (p3); 
\draw [red] (p1) .. controls  ($(O)+.3*(p2)$)  ..  (p3); 

\end{tikzpicture}

\end{document}

By using, say

\path [violet, bend left=30, looseness=1.3]
(p1) edge (p2)
(p3) edge (p4)
(p5) edge (p6)
% since I cannot order points, I'll have 
% pairings like the next one:
(p8) edge (p7)
;

This is what I meant with breaking of symmetry: one of the edges bends the other side, and not towards the center. I cannot reorder data in order to invert the bending-side.

enter image description here

  • 1
    For your question 'Isn't there an option to tell controls .. not to bend that much?', I guess the answer is 'No'. That is because bend left and looseness influence how TikZ creates the control points for you. If you choose the control points yourself, you bypass that logic. The path of the curve is then determined by a mathematical formula. In order for it to look different you have to pick different controls. However, you could make the calculation of the intermediate control point a bit easier by using the barycentric cs coordinate system. Then you don't need to know (p2). – Fritz Sep 25 at 11:04
  • If you want symmetry, use arcs not parabolas. Try \draw [blue] (p1) arc[radius=4, start angle=-45, end angle=-135]; – John Kormylo Sep 25 at 14:43
  • @JohnKormylo I cannot do that, unfortunately, for a large (7!! times 4) number of points. – c.p. Sep 25 at 18:48
6

For your question 'Isn't there an option to tell controls .. not to bend that much?', I guess the answer is No. That is because bend left and looseness influence how TikZ creates the control points for you. If you choose the control points yourself, you bypass that logic. The path of the curve is then determined by a mathematical formula, so in order for it to look different you have to pick different controls.

However, you could make the calculation of the intermediate control point a bit easier by using the coordinate system barycentric cs (see also pgfmanual 13.2.2 Barycentric Systems). Then you don't need to know the coordinate between start and end ((p2) in your example).

The green lines are all possible connections in your example graph, except loops. The red/blue lines show how the barycentric coordinate system works when you change the influence of the coordinate (O).

Example output

\documentclass{article} 
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=1]

\coordinate (O) at (0,0);
\draw (O) circle (4);

\foreach \i in {1,2,...,8} {
    \node[draw,fill=white,circle] (p\i) at (360*\i/8:4)  {\i};
}

% Demonstrate influence of O=\looseness in barycentric cs on (p1)--(p3)
\foreach[evaluate={\col={15*\looseness}}] \looseness in {0, 0.25, 0.5, 0.75, 1, 2, ..., 6} {
    \draw [color=blue!\col!red] (p1) .. controls (barycentric cs:p1=0.5,p3=0.5,O=\looseness) ..  (p3); 
}

% Draw all possible edges 
\tikzstyle{every edge}=[
    draw, green,
    to path={
        .. controls (barycentric cs:\tikztostart=0.5,\tikztotarget=0.5,O=0.3) ..
        (\tikztotarget) \tikztonodes
    },
]
\foreach \i in {1, ..., 8}{
    \foreach \j in {1, ..., 8}{
        \ifnum\i=\j\else
            \draw [green] (p\i) edge (p\j); 
        \fi
    }
}

\end{tikzpicture}
\end{document}
5

With bend left, you should be able to get what you want (unless I totally misundertsood your demand)... but you have to pay attention to the order of the coordinates.

\documentclass{standalone} 
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}


\begin{tikzpicture}[scale=1]


\coordinate (O) at (0,0);
\draw (O)  circle (4);
%  
 \foreach \i in {1,2,...,8} {

 \node[draw,fill=white,circle] (p\i) at ($(O)+(360*\i/8:4)$)  {\i};
   }
\foreach \i/\j in {1/3,2/4,3/5,4/6,5/7,6/8,7/1,8/2}{
\draw [blue] (p\i) .. controls (O) ..  (p\j); 
\draw [red] (p\i) .. controls  ($(O)+.3*(p2)$)  ..  (p\j); 
\draw [green,bend left,looseness=1.5] (p\i) edge (p\j); 
}
\end{tikzpicture}

\end{document}

enter image description here

EDIT A proposal with number sorting so that the actual plot is always done in increasing node numbers.

\documentclass{standalone} 
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}


\begin{tikzpicture}[scale=1]


\coordinate (O) at (0,0);
\draw (O)  circle (4);
%  
 \foreach \i in {1,2,...,8} {

 \node[draw,fill=white,circle] (p\i) at ($(O)+(360*\i/8:4)$)  {\i};
   }
\foreach \ii/\jj [
    evaluate={\ii as \i using ifthenelse(\jj<\ii,int(\jj),int(\ii))},
    evaluate={\jj as \j using ifthenelse(\jj<\ii,int(\ii),int(\jj))},
] in {1/2,3/4,5/6,7/8,7/6}{
\draw [blue] (p\i) .. controls (O) ..  (p\j); 
\draw [red] (p\i) .. controls  ($(O)+.3*(p2)$)  ..  (p\j); 
\draw [green,bend left,looseness=1] (p\i) edge (p\j); 
}
\end{tikzpicture}

\end{document}

enter image description here

  • The problem is that I cannot order the coordinates. (p1) to (p2) doesn't bend as (p2) to (p1), but opposite. That's why I wrote in the title without using bend left. – c.p. Sep 25 at 9:16
  • @c.p. Could you show an example of what you want to achieve ? Also, you say that you cannot order the points, but for instance do you know the total amount of points that you will get or other imprtant parameter of your plot ? – BambOo Sep 25 at 9:27
  • it's more or less double factorial (of 7, I guess 105 diagrams). I cannot order them manually. I'll edit. – c.p. Sep 25 at 9:39
  • @c.p. Just posted an improved version, which sorts nodes by index – BambOo Sep 25 at 10:49
  • thanks, that helps :) – c.p. Sep 25 at 11:38

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.