Sometime datasets assume strange shapes, and often to make easier our computations, we simulate the set of points using approximation of well-known statistic distributions, mixture models, and so on, but as we know the world often is more complex than expected, and an analytical density function is tricky to find out.

Let me show, a different approach, to simulate points belonging to really irregular convex polygons.

The method I propose is based on a kind of

**Markovian Process**, better known under the name of**Iterated Function System (IFS)**. The IFS are famous thanks to the “collage theorem” of Prof.**M. F. Barnsley**that allows amazing image compressions and description of complex phenomena. (I really suggest a deep reading of the book “Fractal everywhere” that you can buy clicking on the Amazoon panel).Just to remark the powerful of the IFS fractals, I plotted the famous fern obtained with 4 affine transformations ( I’ll explain below how IFS works).

The sequence of images shows how a fern can be built following the underlying process.

IFS to generate the fern. To different transformation has been assigned a different color. |

**IFS: how it works**

To generate an IFS fractal you just need a set of affine contractive transformations and for each transformation an associated probability (…of course the sum of the probabilities associated to the transformations must be equal to one!).

So for a given set of affine contractive transformation {a,b,c,d} and the respective probability set {pr_a, pr_b, pr_c, pr_d} you initialize the process from an arbitrary point of the space “P_t0”, and you find the next point of the process applying to it a transformation chosen among the mentioned set with the associated probability.

That's it!

**Generate points in a convex Polygon.**

The process to generate a set of points in a convex polygon is based on the above process, but, instead of using a generic affine transformation, we can use only homothetic contractive transformations.

Procedure:

- Find a set of homothetic affine transformations of the polygon having fixed point in the vertexes of the polygon.

Homothetic transformations with fixed points on vertexes of the polygon |

- Assign equal probability to each transformation
- Trigger the Process starting from a point inside the polygon.

Actually the above procedure works properly also with non concave objects (like straight line):

The above procedure applied to find points belonging to a segment |

Here you are some examples of set for the above procedures.

The set of points obtained for the former polygon. (Changing the contraction factor, you can obtain different coverages). |

As you can see, some points fall above the polygons: Why? Because I initialized the process from point outside the polygon, but the final effect doesn't change |

In the next post we will discuss about the Probability Density Function (PDF) for the points obtained with this procedure and the relation between the PDF and contractive factor.

Stay Tuned!

cristian