Graphics, Figures & TablesDrawing Circles with Dynamic Radii

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
s.david
Posts: 43
Joined: Thu Sep 10, 2009 5:22 pm

Drawing Circles with Dynamic Radii

Post by s.david »

Hello,

I have the following segment of code:

Code: Select all

\documentclass[a4paper,12pt,openany,oneside]{memoir}
\usepackage{tikz}
\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}

    \node (source) at (0,0) [circle,draw] {$S$};
    \node (relay) at (3,2) [circle,draw] {$R$};
    \node (destination) at (6,0) [circle,draw] {$D$};


    \draw [->] (source.60) to node [auto] {} (relay.west);
    \draw [->] (relay.east) to node [auto] {} (destination.120);

\end{tikzpicture}

\end{center}
\end{figure}
\end{document}
Now, I want to draw three circles with three different line types (dashed, thick, very thick, double line, ..., etc.) on the same figure, with radii:

1- The distance from node S to node R.
2- The distance from node R to node D, and
3- The distance from node S to node D.

And write on the largest circle: "Direct", and on the other two: "indirect".

How can I do that?

Thanks in advance

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Drawing Circles with Dynamic Radii

Post by localghost »

I think the »fit« library will be useful. See pgf/tikZ manual (Section 30 - Fitting library, p. 276f).


Best regards
Thorsten
s.david
Posts: 43
Joined: Thu Sep 10, 2009 5:22 pm

Drawing Circles with Dynamic Radii

Post by s.david »

localghost wrote:I think the »fit« library will be useful. See pgf/tikZ manual (Section 30 - Fitting library, p. 276f).


Best regards
Thorsten
It did not work. Anyway, I came with this code:

Code: Select all

\documentclass[a4paper,12pt,openany,oneside]{memoir}
\usepackage{tikz}
\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}[scale=0.75]

\pgfsetfillopacity{0.5}

		
    \draw [very thick,dashed,fill=gray!60](0,0) circle (3.6cm);
    \draw [dashed,fill=gray!20](3,2) circle (3.6cm);
    \draw (0,0) circle (6cm);
    
    \node (source) at (0,0) [circle,draw] {$S$};
    \node (relay) at (3,2) [circle,draw] {$R$};
    \node (destination) at (6,0) [circle,draw] {$D$};


    \draw [->] (source.60) to node [auto] {} (relay.west);
    \draw [->] (relay.east) to node [auto] {} (destination.120);
    \draw [->] (source.east) to node [auto,swap] {} (destination.west);
    
   

\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
But how can I write above each circle in the figure? I tried, but with no use.

Thanks in advance
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Drawing Circles with Dynamic Radii

Post by gmedina »

Hi,

the following code could give you some ideas (it incorporates a solution to the first problem):

Code: Select all

\documentclass[a4paper,12pt,openany,oneside]{memoir}
\usepackage{tikz}
\usetikzlibrary{through}

\begin{document}

\begin{figure}[!ht]
\centering
\begin{tikzpicture}[scale=0.75]
  \pgfsetfillopacity{0.5}

  \node (source) at (0,0) [circle,draw] {$S$};
  \node (relay) at (3,2) [circle,draw] {$R$};
  \node (destination) at (6,0) [circle,draw] {$D$};

  \node (E) [draw, circle through=(relay),very thick,dashed,fill=gray!60,label=below:$Indirect$]
    at (source) {};
  \node (F) [draw, circle through=(destination), dashed,fill=gray!20,label=above right:$Indirect$] 
    at (relay)  {};
  \node (G) [draw, circle through=(destination),label=above:$Direct$] 
    at (source) {};

  \draw [->] (source.60) to node [auto] {} (relay.west);
  \draw [->] (relay.east) to node [auto] {} (destination.120);
  \draw [->] (source.east) to node [auto,swap] {} (destination.west);
\end{tikzpicture}
\end{figure}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
s.david
Posts: 43
Joined: Thu Sep 10, 2009 5:22 pm

Drawing Circles with Dynamic Radii

Post by s.david »

gmedina wrote:Hi,

the following code could give you some ideas (it incorporates a solution to the first problem):

Code: Select all

\documentclass[a4paper,12pt,openany,oneside]{memoir}
\usepackage{tikz}
\usetikzlibrary{through}

\begin{document}

\begin{figure}[!ht]
\centering
\begin{tikzpicture}[scale=0.75]
  \pgfsetfillopacity{0.5}

  \node (source) at (0,0) [circle,draw] {$S$};
  \node (relay) at (3,2) [circle,draw] {$R$};
  \node (destination) at (6,0) [circle,draw] {$D$};

  \node (E) [draw, circle through=(relay),very thick,dashed,fill=gray!60,label=below:$Indirect$]
    at (source) {};
  \node (F) [draw, circle through=(destination), dashed,fill=gray!20,label=above right:$Indirect$] 
    at (relay)  {};
  \node (G) [draw, circle through=(destination),label=above:$Direct$] 
    at (source) {};

  \draw [->] (source.60) to node [auto] {} (relay.west);
  \draw [->] (relay.east) to node [auto] {} (destination.120);
  \draw [->] (source.east) to node [auto,swap] {} (destination.west);
\end{tikzpicture}
\end{figure}

\end{document}
Amazing. It works perfectly, and eliminated the problem of fixed radius circles.

Thank you.

Best regards
Post Reply