# Random point from triangle

I need to get a random point from a triangle composed of 3 points. How can I do that?

If you just want random points uniformly distributed on the triangle, you probably can just find a bounding rectangle to the triangle, and keeping those uniformly distributed points inside the triangle.

For example, I have a 3ds model where I want each face to emit particle. So I have to find random point from each face to emit a particle.

The solution is Barycentric Coordinates t1,t2,t3.

P=t1P1+t2P2+t3*P3 is a point on the plane of the triangle formed by P1,P2,P3 if 0 &lt=t1,t2,t3 &lt=1 and t1+t2+t3=1.

So just assign them 3 random values from the intervall [0,1] and normalize them by dividing by (t1+t2+t3).

Edit:

Something slightly more tricky is needed if you need uniformly distributed points though.

I’m fairly certain that this will give you uniformly distributed homogeneous barycentric coordinates:

``````t1=Uniform(0.0,1.0);
t2=Uniform(0.0,1.0);
if(t1+t2>1.0)
{
t1=1.0-t1;
t2=1.0-t2;
}
t3=1.0-t1-t2;
``````