Generating Randomly distributed points inside a given triangle

1.2k Views Asked by At

Given the cartesian coordinates of three vertices of a triangle $P_1$, $P_2$, $P_3$ I know (have simulated) that I get randomly distributed points by using this protocol:

$s=\text{rand}(0,1)\quad t=\sqrt{\text{rand}(0,1)}$

$P = (1-t)\cdot P_1 + t\cdot\left( (1-s)\cdot P_2 + s\cdot P_3\right )$

where $\text{rand}()$ is the uniform random number generator.

Can someone explain why this works?

Intuitively, this seems like applying the lever rule on the edge between one pair of points, say, $P_2$ & $P_3$ to get a intermediate point $P'$ & then a second lever rule between $P'$ and $P_1$.

What I don't get is why the second lever is drawn from a square root of the first uniform distribution.

2

There are 2 best solutions below

2
On

$$ Q_s=(1-s) P_2 + s P_3 $$ is a convex combination of $P_2$ and $P_3$ and $$ P_{s,t} = (1-t) P_1 + t Q_s $$ is a convex combination of $P_1$ and $Q_s$, hence a point of the convex envelope of $P_1,P_2,P_3$, i.e. the original triangle. If we draw a random point $P$ in the triangle from a uniform distribution, $P=P_{s,t}$ for some $(s,t)\in[0,1]^2$, and the marginal distributions of $s$ and $t$ can be recovered in a straightforward way. For any $\lambda\in[0,1]$, both $$ \mathbb{P}[s\leq \lambda]\qquad \mathbb{P}[t\leq \lambda] $$ can be computed in terms of triangle areas, but while $\mathbb{P}[s\leq \lambda]=\lambda$, $\mathbb{P}[t\leq \lambda]=\lambda^\color{red}{2}$.

So $s$ has a uniform distribution, but the distribution of $t$ is the square root of a uniform distribution.

3
On

That is a tecnique well known in chemistry, for representing mixtures of 3 substances, it is called "Trilinear" coordinates, re for e.g. to https://en.wikipedia.org/wiki/Trilinear_coordinates