<< Back to main.

Horseshoe Mapping (Fractal)

Smile's horsehoe mapping usually serves as a milestone in the research of nonlinear mappings yielding fractals. Strangely, finding code which implements the algorithm is not that easy. Find here Java code for the generation of the horseshoe fractal.

For the mapping

following holds: areas B, C and D lie inside [-1;-1] → [+1;+1]. Applying the mapping f, A, C and E are getting lost, i.e. leave (and never come back into) [-1;-1] → [+1;+1]. B and D first get horizontally squeezed by a factor ALPHA less than 0.5, then stretched vertically by 1/ALPHA (hence greater than 2.0), then bent. As can be seen from the figure, some (small) parts of B and D will get lost as well. Half the height of C is called C2 inside the code below.

Main Class

The extent of the code rather moderate, I do not develop an elaborated design but rather pack everything into one class, which reads as shown in Horseshoe.java

The algorithm lies inside method mapHorseshoe(). The program determines for many random points, if and when iteratedly applying the mapping the point leaves the area given by corners [-1;-1] and [+1;+1].

The output might look like: