How to draw the inversion of a circle in TikZ?

The inversion of a point P and center O is another point P' along the line OP such that the product OP. OP' = k, that is, a constant k. The inversion of a circle, by a point O (not in the circle) is another circle, as in the figure below.

Is it possible to draw the second circle in TikZ as a (correct) inversion of the first? I know it is easy to do translation, rotations and other linear transformations ... but never seen an inversion.

• You are given the circle, the point of inversion (O) and the constant of inversion k, such that, OP . OP' = k. – Paulo Ney Feb 18 '16 at 19:47
• I just checked Wikipedia on inversion geometry and it uses an entirely different definition (still uses OP \times OP' = r^2). – John Kormylo Feb 18 '16 at 19:59
• @JohnKormylo They are equivalent! – Paulo Ney Feb 18 '16 at 20:47
• Consider the line passing through O and center of circle, this gives a diameter of initial circle, compute the two image points, this gives diameter of image circle. Should be easy to translate that into TikZ, but unfortunately I don't know its syntax. – user4686 Feb 18 '16 at 21:22
• Well, what do you have so far? Have you drawn the circle and marked the initial points? – cfr Feb 18 '16 at 21:54

While you are waiting for a TikZ solution, here is a simple way to do your diagram in Metapost. The basic geometry is explained well on Mathworld, (although the diagram there shows inversion of a point outside the circle of inversion; in the case here the roles of P and P' are reversed because P is inside the circle of inversion).

Here I have added the outline of part of the circle of inversion in faint pink to make it slightly more obvious how it works - you could of course remove the pink arc if it's not required.

prologues := 3;
outputtemplate := "%j%c.eps";

vardef invert_point(expr p, k) =
if abs(p)>0:
unitvector p scaled (k/abs(p)) scaled k
else:
origin % strictly this should be a point at infinity
fi
enddef;

vardef invert_path(expr P, k) =
for t=0 step 1/16 until length P-1/16:
invert_point(point t of P, k) --
endfor
if cycle P:
cycle
else:
invert_point(point infinity of P, k)
fi
enddef;

beginfig(1);

path C, C';
pair P, P', Q;

k = 150;
draw subpath (-1.4,1.4) of fullcircle scaled 2k withcolor .8[red,white];

C = fullcircle scaled 72 shifted 100 right;
P = point 1 of C;
C' = invert_path(C, k);
P' = invert_point(P, k);
Q = (origin -- P) intersectionpoint subpath (2,4) of C;

draw origin -- P';
draw origin -- center C' withcolor .5 white;
draw P'     -- center C' withcolor .5 white;
draw Q      -- center C  withcolor .5 white;

draw C;
draw C' withcolor .78 blue;

fill fullcircle scaled 3;
fill fullcircle scaled 3 shifted P;
fill fullcircle scaled 3 shifted Q;
fill fullcircle scaled 3 shifted P';
fill fullcircle scaled 3 shifted center C;
fill fullcircle scaled 3 shifted center C';

label(btex $O$  etex, origin + (-6,3));
label(btex $P$  etex, P      + (+3,7));
label(btex $P'$ etex, P'     + (-3,7));
label(btex $Q$  etex, Q      + (-3,7));
label(btex $C$  etex, point 5.5 of C + (-3,-7));

endfig;
end


Notes

• For simplicity invert_point assumes the circle of inversion is centered at the origin. But it would not be hard to adapt the subroutine to accept an arbitrary circle instead of the radius k.

• Again for simplicity I have provided two different functions here for a path and for a point but you could easily write a single invert function and use if path P and if pair P to pick the right action according to what you passed to it.

• The expression unitvector p scaled (k/abs(p)) scaled k might be more naturally written as unitvector p scaled (k**2/abs(p)) but you will get an arithmetic overflow error if you set k to more than 181. This because 182**2 is greater than 2**15 which is the largest number plain MP allows. To avoid this either code it as I have shown or use mpost -numbersytem=double to process it.

• Don't use this to invert a point at the origin; since you can't easily represent infinity on a finite diagram.

I have worked it out in Tikz the following way.

First, there are two different inversions:

1. the point is inside the inversion circle;
2. the point is outside it.

I'm going to start with the second case. I will draw a circle centred on point "O" (called "k") and search the inversion point of point "P" outside the circle "k".

First thing you need to know is one of the tangent point from "P" to "k". The projection of this point to line "OP" is the inversion point of "P".

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\coordinate (P) at (5,0);
\draw[red,thick,name path=circ1](O)circle(2);
%
% I look for the midpoint of O and P. This point will be the centre of
% an arc whose intersection with k will give me the tangent points
%
\path(O)--coordinate[midway](M)(P);
%
% I draw the arc whose intersection with circle are the 2 tangent points
%
\path[name path=circ2] let
\p1=(O),
\p2=(M),
\n1={veclen(\x2-\x1,\y2-\y1)} in
($(M)+({\n1*cos(130)},{\n1*sin(130)})$) arc (130:230:\n1);
\path[name intersections={of=circ1 and circ2}]
(intersection-1) coordinate (Tg1)
(intersection-2) coordinate (Tg2);
\draw[blue]
(A)--(Tg1)
(O)--node[midway,left,black]{$\mathtt{r}$}(B)
(O)--(A);
%
% Here we are. This projection is the inversion of point P with regards
% to circle k
%
\draw[orange](Tg1)--($(O)!(Tg1)!(P)$)coordinate(InvP);
%
\draw[black,line width=.75,fill=white]
(P)circle(1.5pt)node[black,below]{$\mathtt{P}$};
\draw[black,line width=.75,fill=white]
(O)circle(1.5pt)node[black,below]{$\mathtt{O}$};
\draw[black,line width=.75,fill=white]
(Tg1)circle(1.5pt)node[black,below]{$\mathtt{Tg1}$};
\draw[black,line width=.75,fill=white]
(InvP)circle(1.5pt)node[black,below]{$\mathtt{P'}$};
\node at (-1.75,0) {$\symtt{k}$};
\end{tikzpicture}
\end{document}


When the point is inside the circle, all we have to do is find the perpedicular line from OP, find the intersection of this line with circle k (call it TgP), draw the tangent line from this point and find its intersection with OP.