MATLAB: Create/choose a rondom point from an existed data matrix

MATLAB

I have data matrix (3000 * 3) and then I created from these data delaunay triangles with vertices P0, P1 and P2. I want to establish rondom points Pr which come originally from the data matrix (3000 * 3) and these random points are located inside the generated delaunay triangles vertices P0, P1 and P2. Could you please help me to achieve this ?

Best Answer

I will give an answer in terms of a single triangle with vertices at P0, P1, and P2, (either in 2D or 3D.) Define
r1 = rand;
r2 = sqrt(rand); % <-- The square root operation is important here
Then the value P
P = (1-r2)*P0+r2*(r1*P1+(1-r1)*P2);
will be a random point within the triangle P0P1P2, with a statistically uniform probability distribution therein.
I will leave the problem of doing this for the entire triangulation to you. It can easily be vectorized.