# How to draw a circle whose radius is a multiple of the distance of two points in TikZ?

The following is the MWE for my figure:

\documentclass{article}
\usepackage{caption}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows,shapes,calc,intersections,through,backgrounds}

\begin{document}
\begin{figure}[b]
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\coordinate (a) at (1,4);
\coordinate (p) at (1,5);

\draw(a) let \p1 = ($(a) - (p)$) in circle (\pgfmathparse{veclen(\x1,\y1) * 3}\pgfmathresult);
\end{tikzpicture}
\end{figure}
\end{document}


I'm getting the following error for this:

! Incomplete \iffalse; all text was ignored after line 12.


I'm not sure what is the issue here - some help would be appreciated!

## 4 Answers

You do not need the \pgfmathparse..\pgfmathresult. Note the extra pair of brackets around the calculation in the code below, which hides the parenthesis of the veclen function from the delimiters of the circle radius.

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (1,4);
\coordinate (p) at (1,5);
\draw(a) let \p1 = ($(a) - (p)$) in
circle ({veclen(\x1,\y1)*3});

\fill (a) circle[radius=1pt] node[right]{a};
\fill (p) circle[radius=1pt] node[right]{p};
\end{tikzpicture}
\end{document} • That did the trick! – TCSGrad Aug 22 '13 at 18:50

Do not use \pgfmathparse in coordinates or other values of TikZ.

TikZ will parse nearly everything through PGF math anyway which is also the reason it doesn’t work because you can’t use content that is not fully expandable.

You could have used

\draw(a) let \p1 = ($(a) - (p)$) in \pgfextra{\pgfmathparse{veclen(\x1,\y1) * 3}}
circle [radius=\pgfmathresult pt];


but others have already given better solutions than that.

I want to propose another option: the through library.

It has only one purpose: drawing a circle through on specific point. With the calc library you can now write

\node[draw] at (a) [circle through=($(a)!3!(p)$)] {};


with the same effect.

Without the calc library, this can be reduced to

\node[draw] at (a) [circle through=(p), scale=3] {};


## Code

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{through,calc}
\begin{document}
\begin{tikzpicture}[thick, dot/.style={shape=circle,inner sep=+0pt, minimum size=+2pt, fill, label={#1}}]
\coordinate[dot=a] (a) at (1,4);
\coordinate[dot=p] (p) at (1,7);

\foreach \cnt[count=\Cnt] in {.25, .5, 1, 1.5, 2}
\node[draw, color=red!\Cnt 0!blue, label={[inner sep=+1pt, red!\Cnt 0!blue]below:$f = \cnt$}] at (a) [circle through=($(a)!\cnt!(p)$)] {};
\end{tikzpicture}
\begin{tikzpicture}[thick, dot/.style={shape=circle,inner sep=+0pt, minimum size=+2pt, fill, label={#1}}]
\coordinate[dot=a] (a) at (1,4);
\coordinate[dot=p] (p) at (1,5);

\node[draw] at (a) [circle through=(p), scale=3] {};
\end{tikzpicture}
\end{document}


## Output  • To me, the syntax '($(a)!3!(p)$)' is hardly the preferred solution, as its not very readable - the solution without the calc library is more readable IMHO. Perhaps, if you explain the syntax of the calc version, it would be more intuitive? – TCSGrad Aug 22 '13 at 19:50
• @TCSGrad I agree, calc’s syntax often times is too short. Though, this is relatively easy: The coordinate is three times away from a as p. (a)!0!(p) gives you a, (a)!1!(p) gives you p and (a)!.5!(p) gives you the point that is halfway between a and p. This syntax is described in the PGF manual, subsection 13.5.3 “The Syntax of Partway Modiers” (pp. 139ff). I prefer the calc-less solution because you do not have to specify the center point a twice. – Qrrbrbirlbel Aug 22 '13 at 19:58

Since you already used let..in syntax in your code, why not continue using that syntax to compute the required radius (storing it in, say \n1) instead of using \pgfmathparse/\pgfmathresult?

I mean the following:

\begin{tikzpicture}
\coordinate (a) at (1,4);
\coordinate (p) at (1,5);
\foreach \p in {a,p} \fill[red] (\p) circle(1mm);

\draw[very thick]
let \p1 = ($(a) - (p)$),
\n1 = {3*veclen(\x1,\y1)}
in (a) circle (\n1);
\end{tikzpicture} With PSTricks

## Single

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid=true](-5,-5)(5,5)
\pstGeonode(0,0){X}(0,2){Y}
\pstCircleOA[DistCoef=2,Radius=\pstDistAB{X}{Y}]{X}{<ignored>}
\end{pspicture}
\end{document} ## Multiple

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\multido{\r=.5+.1}{15}{%
\begin{pspicture}[showgrid=true](-5,-5)(5,5)
\pstGeonode(0,0){X}(0,2){Y}
\pstCircleOA[DistCoef=\r,Radius=\pstDistAB{X}{Y}]{X}{<ignored>}
\end{pspicture}}
\end{document} • Tsunami propagation in action... – kiss my armpit Aug 23 '13 at 9:56