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.

How to draw the curved line inside the red circle in this picture : enter image description here

MWE

\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usetikzlibrary{shapes.geometric,arrows,positioning,fit,calc,backgrounds}

\begin{document}
   \begin{tikzpicture}
      \draw (-2,0) circle (.4cm) node[below=.5cm, align=center] {Client};
      \draw[color=red] (0,0) circle (.4cm) node[below=.5cm, text width=1.5cm, color=black, align=center] {Homme du milieu};
      \draw (2,0) circle (.4cm) node[below=.5cm, align=center, text width=1cm] {Serveur web};
      \draw[color=blue] (-2, 0) -- (-.4,0);
      \draw[color=blue] (.4, 0) -- (2,0);

      \draw[-, color=red] (-.4,0) to[out=-30,in=100,looseness=2] (.4,0) ;
   \end{tikzpicture}
\end{document}

How does function the to[out=-30,in=100,looseness=2] work?. I read an answer that suggested using it for making curved paths but I don't know how it works.

share|improve this question

4 Answers 4

up vote 15 down vote accepted

I suggest to use named circle nodes. If the red one is called hdm you can use something like

\draw[red,looseness=1.5] (hdm.west) to[out=70,in =110] (hdm.center) to [out=-70,in=-110](hdm.east); 

to get

enter image description here

Code:

\documentclass[tikz,margin=5mm]{standalone}
\begin{document}
   \begin{tikzpicture}[mycircle/.style={draw,circle,minimum size=.8cm}]
      \node[mycircle,label=below:Client](client)at (-2,0){};
      \node[mycircle,red,label={[text width=1.5cm,align=center]below:Homme du milieu}](hdm){};
     \node[mycircle,label=below:Server web](sweb)at (2,0){};
      \draw[color=blue] (client.center) -- (hdm) -- (sweb.center);
      \draw[red,looseness=1.5] (hdm.west) to[out=70,in =110] (hdm.center) to [out=-70,in=-110](hdm.east);
   \end{tikzpicture}
\end{document}

Here is a picture to explain how

\draw[looseness=1.5] (hdm.west) to[out=70,in =110] (hdm.center) to [out=-70,in=-110](hdm.east);

works (looseness=0.5 is green, looseness=1.5 is orange and loosness=2 is blue):

enter image description here

Code:

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{angles,quotes}
\usepackage{textcomp}
\begin{document}
   \begin{tikzpicture}
      [myangle/.style={draw=red,thick,angle radius=1cm,fill=blue!10,fill opacity=0.5,}]
      \node[draw,circle,minimum size=8cm](hdm){};
      \foreach \l/\c in {0.5/green,1.5/orange,2/blue}
        \draw[thick,dashed,\c,looseness=\l] 
          (hdm.west) to[out=70,in =110] node[below]{\l}(hdm.center) to [out=-70,in=-110](hdm.east);
      \draw[help lines,thick]([xshift=-1cm]hdm.west)--([xshift=1cm]hdm.east)coordinate(H);
      \draw(hdm.west)coordinate[label=below left:hdm.west](A)--+(70:2)coordinate(B)
           (hdm.center)coordinate[label=below left:hdm.center](C)--+(110:2)coordinate(D)--+(-70:2)coordinate(E)
           (hdm.east)coordinate[label=above right:hdm.east](F)--+(-110:2)coordinate(G);
      \pic[myangle,->,"70\textdegree"]{angle=C--A--B};
      \pic[myangle,->,"110\textdegree"]{angle=F--C--D};
      \pic[myangle,<-|,"-70\textdegree"]{angle=E--C--F};
      \pic[myangle,<-,"-110\textdegree"]{angle=G--F--H};
   \end{tikzpicture}
\end{document}
share|improve this answer
1  
Nice answer. As your angles are oriented, they should be +70 and +110 instead of -70 and -110. –  Tarass Jun 9 at 17:48
1  
Thanks for the hint. I have changed the orientation of the two angles. –  esdd Jun 9 at 18:39

For completness, another answer which uses pic to store the "ying-yang" shape. This feature requires PGF 3.0.0

Styles and pic definitions

\tikzset{
    entity/.style = {
        draw, circle, minimum size=0.8cm
    },
    mylabel/.style = {
        below=.5cm, text centered,
        text width=2cm
    },
    ying yang/.pic = {
     \node[entity, pic actions] (-edge) at (0,0) {};
     \draw let \p1=($(-edge.west)-(-edge.center)$),
               \n1={veclen(\p1)-0.5\pgflinewidth}
           in (-\n1,0) .. controls +(90:0.8*\n1) and +(90:0.8*\n1)
              .. (0,0) .. controls +(-90:0.8*\n1) and +(-90:0.8*\n1)
              .. (\n1,0);
    },
}

With above settings, it is possible to \draw pic {ying yang} anywhere, and also some additional styles can be "passed" to the pic (line color, fill color, line width). In addition, we can also give a name to the shape when it is drawn, for example: \draw pic (A) {ying-yang}. Sice the code of the pic (above) defines a node name (-edge), both names are combined, and the name (A-edge) can be used later in the tikzpicture to refer to the circular shape of the ying-yang.

Now, some examples of use of this pic.

As requested by the OP

This is the code of the figure requested by the OP, using this new pic:

\begin{tikzpicture}
    \node[entity] (client) at (-2,0) {};
    \draw (0,0) pic (middleman) [fill=red!20, draw=red] {ying yang};
    \node[entity] (server) at (2,0) {};
    % Label the nodes
    \path (client)         node[mylabel] {Client}
          (server)         node[mylabel] {Serveur\\web}
          (middleman-edge) node[mylabel] {Home du millieu};
    % Connect with lines
    \draw (client.center) -- (middleman-edge) -- (server.center);
\end{tikzpicture}

Result:

Result

Sloped

One advantage of this pic is that it can be placed anywhere in a curve, and even sloped:

\begin{tikzpicture}
    \draw (0,0) .. controls +(2,0) and +(-2,0).. (3,3)
       foreach \t in {0,0.2,...,1.0} {
          pic[pos=\t, fill=yellow!20, sloped] {ying yang}
    };
\end{tikzpicture}

Sloped

Automatic intersections

Lines drawn to the (name-edge) refer to the inner circle node, so the intersections with its shape are automatically computed. In the following example, the pic is drawn without inner fill, but the lines drawn from outside stop at the edge, not at the center:

\begin{tikzpicture}
    \node at (0,0) {A};           % Simply a char
    \draw    (0,0) pic (A) {ying yang};  % Not filled, the A can be seen below

    % Draw lines to A-edge. Intersections automatically computed
    \foreach \a in {0,10,...,350}
       \draw (\a:2) -- (A-edge);
\end{tikzpicture}

Edges

Anchor names

Not only we have acces to (name-edge), but also to its anchors (eg: (name-edge.north), (name-edge.center) and eve (name-edge.30) etc.)

\begin{tikzpicture}
    \draw    (0,0) pic (A) [fill=blue!20] {ying yang};
    \draw    (2,0) pic (B) [fill=green!20, thick] {ying yang};
    \draw[->] (A-edge.north) to[out=90, in=30] (B-edge.45);
\end{tikzpicture}

Result

share|improve this answer

This is a possible solution where arc is used to draw half cycle of a circle

  \draw[-, color=red] (-0.4,0) arc (180:0:0.2cm)  (0,0) arc (-180:0:0.2cm);

enter image description here

Code

\documentclass[tikz,border=1cm]{standalone}
\usepackage[utf8]{inputenc}
\usetikzlibrary{shapes.geometric,arrows,positioning,fit,calc,backgrounds}


\begin{document}
   \begin{tikzpicture}
      \draw (-2,0) circle (.4cm) node[below=.5cm, align=center] {Client};
      \draw[color=red] (0,0) circle (.4cm) node[below=.5cm, text width=1.5cm, color=black, align=center] {Homme du milieu};
      \draw (2,0) circle (.4cm) node[below=.5cm, align=center, text width=1cm] {Serveur web};
      \draw[color=blue] (-2, 0) -- (-.4,0);
      \draw[color=blue] (.4, 0) -- (2,0);
      \draw[-, color=red] (-0.4,0) arc (180:0:0.2cm)  (0,0) arc (-180:0:0.2cm);
   \end{tikzpicture}
\end{document}
share|improve this answer

Here is another solution with the use of controls:

\draw[-, color=red] (-0.4,0) to[controls=+(80:0.2) and +(100:0.2)]  (0,0) to[controls=+(-80:0.2) and +(-100:0.2)] (.4, 0);

Full code:

\documentclass[tikz,border=1cm]{standalone}
\usepackage[utf8]{inputenc}
\usetikzlibrary{shapes.geometric,arrows,positioning,fit,calc,backgrounds}


\begin{document}
   \begin{tikzpicture}
      \draw (-2,0) circle (.4cm) node[below=.5cm, align=center] {Client};
      \draw[color=red] (0,0) circle (.4cm) node[below=.5cm, text width=1.5cm, color=black, align=center] {Homme du milieu};
      \draw (2,0) circle (.4cm) node[below=.5cm, align=center, text width=1cm] {Serveur web};
      \draw[color=blue] (-2, 0) -- (-.4,0);
      \draw[color=blue] (.4, 0) -- (2,0);
      \draw[-, color=red] (-0.4,0) to[controls=+(80:0.2) and +(100:0.2)]  (0,0) to[controls=+(-80:0.2) and +(-100:0.2)] (.4, 0);
   \end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
I will appreciate if you give explanation of how it work. –  user230137 Jun 9 at 14:11
    
@user230137 It just draws bezier curves with control points at 0.2cm away at 80 degrees for example. For more, section 70.3 of pgfmanual, pages 753--756. –  Harish Kumar Jun 9 at 14:13

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.