Speeding up RegionPlot for iterated function system fractals
This should work a bit faster. The trick is to use BoundaryDiscretizeRegion
in each step to convert the internal representation to a single polygonal line. The second ingedient is to use machine precision numbers; these are much faster for numerical computations.
θ = ArcTan[0.5];
A = 1/Sqrt[5] RotationMatrix[-θ];
vecs = Developer`ToPackedArray@N@{{0, 1/Sqrt[5]}, {1/5 + 2/5, 1/Sqrt[5] - 1/5 + 2/5}, {2/5 + 2/5, 1/Sqrt[5] - 1/5 - 1/5}, {2/5 - 1/5, 1/Sqrt[5] - 2/5 - 1/5}, {2/5, 1/Sqrt[5] - 1/5}};
step[sq_] := BoundaryDiscretizeRegion[
RegionUnion@Table[TransformedRegion[sq, AffineTransform[{A, v}]], {v, vecs}]
]
MList = NestList[
step,
MeshRegion[N@{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, Polygon[{{1, 2, 3, 4}}]],
8
];
GraphicsGrid[
Partition[MList, 3],
ImageSize -> Full
]
With a little refactoring of your code, and with the use of some undocumented functionality:
θ = ArcTan[1/2];
sqCreate[{x0_, y0_}, h_] := Polygon[{{x0, y0}, {x0 + h, y0}, {x0 + h, y0 + h}, {x0, y0 + h}}]
fullSimil[sq_Polygon] := Map[First, Graphics`PolygonUtils`PolygonCombine[
Table[Polygon[AffineTransform[{RotationMatrix[-θ]/Sqrt[5], pos}] @@ sq],
{pos, {{0, 1/Sqrt[5]}, {3/5, 1/Sqrt[5] + 1/5}, {4/5, 1/Sqrt[5] - 2/5},
{1/5, 1/Sqrt[5] - 3/5}, {2/5, 1/Sqrt[5] - 1/5}}}]]]
Partition[BoundaryDiscretizeGraphics /@ NestList[fullSimil, sqCreate[{0, 0}, 1], 8],
3] // GraphicsGrid