Today I decided to make an attempt at the Sierpiński triangle fractal using the Chaos Game algorithm.
The idea behind this algorithm is extraordinarily simple! Starting from a random point inside the triangle, repeatedly jump halfway to a random vertex. Despite the apparent randomness, a beautiful fractal pattern emerges.
The trickiest part was determining if a randomly generated point falls inside the triangle. I used barycentric coordinates for this:
Given a point P and triangle vertices A, B, C, we calculate three weights (λ₁, λ₂, λ₃). If all three are non-negative, the point is inside!