# Inverted version of Sierpinski triangle

In Michael Trott's The Mathematic Guidebook for Graphics, Section 1.5.1, he first does this:

SierpinskiTriangle[1] = Polygon[{{-1, 0}, {1, 0}, {0, Sqrt[3.]}}];
SierpinskiTriangle[n_Integer] :=
N[Flatten[
SierpinskiTriangle[n] =
SierpinskiTriangle[n - 1] /. {Polygon[{a_, b_, c_}] ->
{
Polygon[{a, (a + b)/2, (a + c)/2}],
Polygon[{(a + b)/2, b, (b + c)/2}],
Polygon[{(a + c)/2, (b + c)/2, c}]
}}]]


Which I did get to work. On the next page, he does this:

Show[Table[Graphics[{Hue[Sin[n]], SierpinskiTriangle[n]}], {n, 8}],
PlotRange -> All, AspectRatio -> Automatic]


Which gives this image.

Then he says "Here is the inverted version of the last picture."

Show[% /. Polygon[l_] :>
Polygon[#/#.# & /@ (# - {0, Sqrt[3.]/3} & /@ l)]]


Which gives this image:

Unfortunately, there is not an index with the textbook, so I cannot find where this might be first explained (the inverted version of a picture).

Can someone explain what is going on here and how it works? So far, I've tried this:

#/#.# & /@ (# - {0, Sqrt[3.]/3} & /@ {{-1, 0}, {1, 0}, {0, Sqrt[3.]}})


Which gives this output:

{{-0.75, -0.433013}, {0.75, -0.433013}, {0., 0.866025}}


But I am still not sure what it going on. Any help in understanding the inverted version of the last picture would be appreciated. Thanks.

• I'd like to thank my colleagues for this help. Wonderful suggestions and examples. I'm devoting my time to learning from this help. Thanks. Jun 23, 2017 at 4:25

Yes, as the other people noted, this geometric transformation called inversion is just mapping coordinate $r$ in a polar coordinate system onto the coordinate $1/r$ (the other coordinate - angle - stays the same). One just needs to define the center of such polar coordinate system, and its unit circle.

If you transform an infinite straight line with this method, point by point, it will map to a circle (not the unit circle, but another one). Since $r \times {1/r} = 1$, that circle will be mapped (with the same transformation) to the straight line from the beginning. Amazing, right?

In your case, imagine the coordinate origin in the center of the largest triangle, and the unit circle as the circumscribed circle of that triangle. In such setup, all smaller triangles in the first picture would be transformed to the curved areas in the second picture.

More on inversion in Mathematica can be found in the article "Inversive Geometry" in Mathematica journal.

A picture from the article:

In this picture, the gray circle is the unit circle, and grayish triangle is inverted to yellow area. The yellow area, if inverted, would become the triangle again.

If you are interested in this topic, the article "Generating fractal patterns by using p-circle inversion", authored by Ramirez, Rubiano, Zlobec, discusses some advanced topics on inversion and fractals like Sierpinski triangle.

Here are two illustrations from the article:

The last one is the inversion of Hilbert curve.

I believe points at $(r, \theta)$ are mapped to $(1/r, \theta)$.

Just to illustrate inversion of Sierpinski triangle in circle (with translated centre):

f[{a_, b_, c_}] :=
With[{r = {a, b, c}}, Map[Function[x, (x + #)/2], r] & /@ r]
sg[n_, {a_, b_, c_}] := NestList[Join @@ (f /@ #) &, {{a, b, c}}, n]
tr[{x_, y_}] := {Cos[ArcTan[x, y]], Sin[ArcTan[x, y]]}/Norm[{x, y}]
pts = {{-1, 0}, {1, 0}, {0, Sqrt[3.]}};
g1 = Graphics[
MapIndexed[{Hue[Sin[#2[[1]]]], Polygon[#1]} &, sg[8, pts]],
ImageSize -> 200];
tsg[n_] := sg[n, pts] /. {x_, y_} :> tr[{x, y} - {0, Sqrt[3.]/3}]
g2 = Graphics[MapIndexed[{Hue[Sin[#2[[1]]]], Polygon[#1]} &, tsg[8]],
ImageSize -> 200];
g3 = Show[Graphics[Circle[]], g2,
Graphics[
Translate[
MapIndexed[{Hue[Sin[#2[[1]]]], Polygon[#1]} &,
sg[8, pts]], {0, -Sqrt[3]/3}]], ImageSize -> 200];
Row[{g1, g2, g3}]


To perhaps elucidate David Stork's answer, I convinced myself of the transformation as follows:

CoordinateTransform["Polar" -> "Cartesian", {rho, theta}]
#/#.# & @ %
CoordinateTransform["Cartesian" -> "Polar", %];
FullSimplify[%, {rho >= 0, 0 <= theta <= Pi}]

(* Out: {1/rho, theta} *)


The rest of the transformation rule is a vertical translation; it appears to me that this is done essentially to avoid division by zero in the transformation.