I just want to use some simple vector math to explain the barycentric coordinates solution which Andreas had given, it will be way easier to understand.
- Area A is defined as any vector given by s * v02 + t * v01, with condition s >= 0 and t >= 0. If any point inside the triangle v0, v1, v2, it must be inside Area A.
- If further restrict s, and t belongs to [0, 1]. We get Area B which contains all vectors of s * v02 + t * v01, with condition s, t belongs to [0, 1]. It is worth to note that the low part of the Area B is the mirror of Triangle v0, v1, v2. The problem comes to if we can give certain condition of s, and t, to further excluding the low part of Area B.
- Assume we give a value s, and t is changing in [0, 1]. In the following pic, point p is on the edge of v1v2. All the vectors of s * v02 + t * v01 which are along the dash line by simple vector sum. At v1v2 and dash line cross point p, we have:
(1-s)|v0v2| / |v0v2| = tp|v0v1| / |v0v1|
we get 1 - s = tp, then 1 = s + tp. If any t > tp, which 1 < s + t where is on the double dash line, the vector is outside the triangle, any t <= tp, which 1 >= s + t where is on single dash line, the vector is inside the triangle.
Then if we given any s in [0, 1], the corresponding t must meet 1 >= s + t, for the vector inside triangle.
So finally we get v = s * v02 + t * v01, v is inside triangle with condition s, t, s+t belongs to [0, 1]. Then translate to point, we have
p - p0 = s * (p1 - p0) + t * (p2 - p0), with s, t, s + t in [0, 1]
which is the same as Andreas' solution to solve equation system
p = p0 + s * (p1 - p0) + t * (p2 - p0), with s, t, s + t belong to [0, 1].