# How to sample points on a triangle surface in 3D?

To take random uniform points inside a triangle Triangle Point Picking method is used. But this is for 2D points, how can I take random points from a triangle that is defined by 3 arbitrary 3D points?

In other words, let's say I have 3 points in 3D space, and these points define a plane, how can I take random points on the plane such that my points are uniformly sampled inside the triangle that is defined by these 3 points?

• You can probably project onto the xy, xz, or yz planes, pick a point, and then project back up. The jacobian of these maps will be constant, so my guess is that uniformly of choice is not destroyed. Oct 24, 2013 at 18:30
• Yeah, I thought of this also, but I was avoiding extra calculation. I mean, let's say that I project onto xy plane and pick points, when back projecting I need to calculate z value of all points using the first 3 points z value. And beside that I'm not sure if it is still be uniform, can you explain it little bit more detailed? What do you mean by jacobian will be constant? Oct 24, 2013 at 18:38

The same exact algorithm should work in $3D$ too: $$\vec{x} = \vec{v_1} + a (\vec{v_2} -\vec{v_1}) + b (\vec{v_3} -\vec{v_1})$$ Where $a,b$ are uniformly distributed in $[0,1]$ and the $\vec{v}$'s are the triangle vertices in $3D$.

• I'll be back, after I try this :) Oct 24, 2013 at 18:41
• This will not work in some cases, such as when $a$ and $b$ are both $1$. In that case, $x$ will be $v_2 + v_3 - v_1$, which is probably not inside the triangle.
– Joel
Sep 9, 2015 at 5:37
• Important note: if $a + b >= 1$ then it will extend past the triangle. In such a case, set $a = 1 - a$ and $b = 1 - b$. Aug 3, 2017 at 22:58

As mentioned in the comments, this formulation is not guaranteed to give you points on the triangle. The correct formulation is as follow:

$$P = (1 - \sqrt{a})v1 + (\sqrt{a} (1 - b))v2 + (b \sqrt{a})v3$$

where $$a, b \sim U[0, 1]$$.