Barycentric Coordinates

Given a triangle between points A, B, and C, each point X on the surface of the triangle can be represented by a weighted sum of the corners:

X = a*A + b*B + c*C

where a, b, and c are numbers between 0 and 1 and a+b+c = 1.

These numbers are called the barycentric coordinates of the point X. There is one unique set of barycentric coordinates for each point on the triangle.

Examples

The center of gravity of the triangle is given by the barycentric coordinates (1/3, 1/3, 1/3): X = 1/3 A + 1/3 B + 1/3 C = (A+B+C)/3.

If one of the barycentric coordinates is zero, the point X must lie on the opposite edge. For instance:

if a=0, X = b*B + c*C

where b+c=1

This means that X is on the line segment BC.

If a=1, on the other hand, then b=c=0, and X must be exactly the point A.