Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My favorite way to draw the Sierpinski triangle is Monte Carlo:

1. Pick a point which is in the triangle (e.g. one of the corners of the triangle). Draw that point.

2. Choose one corner of the triangle at random.

3. Move to the point half way between your current point and the chosen corner. Draw that point.

4. Repeat steps 2-3 as long as desired.

Obviously this only ever reaches a countable subset of the triangle based on where you start, but that subset is everywhere dense in the triangle so it doesn't matter.

You can also start at an arbitrary point that's not actually in the triangle. If you discard the first k (say 10) iterations you'll still get something visually indistinguishable from a Sierpinski triangle.

You can also do this with other self-similar fractals, you just have to find the right set of transformations to use. It's quite fun watching the random points coalesce into the shape of the fractal.



These sets of transforms are known as iterated function systems (IFS), and the algorithm dubbed "the chaos game" by Barnsley. If I recall correctly the algorithm actually distributes uniformly over a probability measure supported by the set, so for picture-making purposes it is typically done with a probability associated with each transforms chosen to even out the visitation (otherwise some details will take forever to be seen).

The whole area is a consequence of Banach's fixed point principle (a very fundamental result), with Hutchinson I think extending it to unions of contractive maps.

Math has many beautiful corners.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: