barycentric coordinates are also often referred to as area coordinates. They are extremely useful in mathematics and engineering, being used often for the evaluation of functions over triangles.

Consider a triangle defined by the three vertexes v1, v2 and v3. Any point r inside that triangle can be written in terms of barycentric coordinates β1, β2 and β3 as

r = β1 v1 + β2 v2 + β3 v3

where the barycentric coordinates are constrained by the relationship

β1 + β2 + β3 = 1

This operation represents a linear interpolation of the triangle's three vertex coordinates. Any point inside the triangle may be found through each unique combination of barycentric coordinates.

Consider now that you have a triangle as defined above, and some scalar function P defined only at each vertex, i.e. you've got P1, P2 and P3, and you wish to interpolate a value at some point r inside the triangle. You can use the formula above to obtain the interpolated value P(r) if you find the barycentric coordinates for point r.

We can use the relationships above to solve for β1, β2 and β3 in terms of vertex coordinates v1, v2, and v3. Define the components of each vector as

v1 = (x1, y1, z1)
v2 = (x2, y2, z2)
v3 = (x3, y3, z3)

Given a known point (x, y, z) inside the triangle, the barycentric expansion is

x = β1 x1 + β2 x2 + β3 x3
y = β1 y1 + β2 y2 + β3 y3
z = β1 z1 + β2 z2 + β3 z3

subject to the constraint

β1 + β2 + β3 = 1

This represents three equations in two unknowns, since

β3 = 1 - β1 - β2

so, making this substitution

x = β1 x1 + β2 x2 + (1 - β1 - β2) x3
y = β1 y1 + β2 y2 + (1 - β1 - β2) y3
z = β1 z1 + β2 z2 + (1 - β1 - β2) z3

Rearranging, this is

β1(x1 - x3) + β2(x2 - x3) + x3 - x = 0
β1(y1 - y3) + β2(y2 - y3) + y3 - y = 0
β1(z1 - z3) + β2(z2 - z3) + z3 - z = 0

Solving for β1 and β2 yields

β1 = (B*(F + I) - C*(E + H))/(A*(E + H) - B*(D + G))
β2 = (A*(F + I) - C*(D + G))/(B*(D + G) - A*(E + H))

where

A = x1 - x3
B = x2 - x3
C = x3 - x
D = y1 - y3
E = y2 - y3
F = y3 - y
G = z1 - z3
H = z2 - z3
I = z3 - z

and β3 is found from the other two.



If you find these relationships useful let me know.