Computational exploration of Barycentric coordinate system​
​by Peter C . Burbery
In geometry, a barycentric coordinate system is a coordinate in which the location of a point is specified by reference to a simplex (a triangle for points in a plane, a tetrahedron for points in three-dimensional space, etc.). The barycentric coordinates of a point can be interpreted as masses placed at the vertices of the simplex, such that the point is the center of mass (or barycenter) of these masses. These masses can be zero or negative; they are all positive if an only if the point is inside the simplex.
Every point has barycentric coordinates, and their sum is not zero. Two tuples of barycentric coordinates specify the same point if and only if they are proportional; that is to say, if one tuple can be obtained by multiplying the elements of the other tuple by the same non-zero number. Therefore, barycentric coordinates are either considered to be defined up to multiplication by a nonzero constant, or normalized for summing to unity.
Barycentric coordinates were introduced by August Ferdinand Möbius in 1827. They are special homogeneous coordinates. Barycentric coordinates are strongly related with Cartesian coordinates, and more generally, to affine coordinates (see Affine Space § Relationship between barycentric and affine coordinates).
Barycentric coordinates are particularly useful in triangle geometry for studying properties that do not depend on the angles of the triangle, such as Ceva's theorem. In computer-aided design, they useful for defining some kinds of Bezier surfaces.

Conversion between barycentric and Cartesian coordinates

In[]:=

Edge Approach

Given a point r in a triangle's plane one can obtain the barycentric coordinates
λ
1
,
λ
2
,
and
λ
3
fromtheCartesiancoordinates(x,y)
or vice versa.
We can write the Cartesian coordinates of the point r in terms of the Cartesian components of the triangle vertices
r
1
,
r
2
,
r
3
where
r
i
=(
x
i
,
y
i
)
and in terms of the barycentric coordinates of r as:
x=
λ
1
x
1
+
λ
2
x
2
+
λ
3
x
3
y=
λ
1
y
1
+
λ
2
y
2
+
λ
3
y
3
That is, the Cartesian coordinates of any point are a weighted average of the Cartesian coordinates of the triangle's vertices, with the weights being the point's barycentric coordinates summing to unity.
To find the reverse transformation, from Cartesian coordinates to barycentric coordinates, we first substitute
λ
3
=1-
λ
1
-
λ
2
into the above to obtain
x=
λ
1
x
1
+
λ
2
x
2
+(1-
λ
1
-
λ
2
)
x
3
y=
λ
1
y
1
+
λ
2
y
2
+(1-
λ
1
-
λ
2
)
y
3
Rearranging this is
λ
1
(
x
1
-
x
3
)+
λ
2
(
x
2
-
x
3
)+
x
3
-x=0
λ
1
(
y
1
-
y
3
)+
λ
2
(
y
2
-
y
3
)+
y
3
-y=0
This linear transformation may be written more succinctly as
T·λ=r-
r
3
where λ is the vector of the first two barycentric coordinates, r is the vector of Cartesian coordinates and T is the matrix given by
T=
x
1
-
x
3
x
2
-
x
3
y
1
-
y
3
y
2
-
y
3

In[]:=
(*Comment.IwanttomaketheTnotitalicasavector*)
Now the matrix T is invertible since
r
1
-
r
3
and
r
2
-
r
3
are linearly independent (if this were not the case, then
r
1
,
r
2
, and
r
3
would be collinear and would not form a triangle). Thus, we can rearrange the above equation to get:
λ
1
λ
2
=
-1
T
(r-
r
3
)
Finding the barycentric coordinates has thus been reduced to finding the 2x2 inverse matrix of T, an easy problem.
Explicitly, the formulae for the barycentric coordinates of point r in terms of its Cartesian coordinates
(x,y)
and in terms of the Cartesian coordinates of the triangles vertices are:
λ
1
=
(
y
2
-
y
3
)(x-
x
3
)+(
x
3
-
y
3
)
det(T)
=
(
y
2
-
y
3
)(x-
x
3
)+(
x
3
-
y
3
)
(
y
1
-
y
3
)(
x
1
-
x
3
)+(
x
3
-
x
2
)(
y
1
-
y
3
)
λ
2
=
(
y
3
-
y
1
)(x-
x
3
)+(
x
1-
x
3
)(y-
y
3
)
det(T)
=
(
y
3
-
y
1
)(x-
x
3
)+(
x
1-
x
3
)(y-
y
3
)
(
y
2
-
y
3
)(
x
1
-
x
3
)+(
x
3
-
x
2
)(
y
1
-
y
3
)
λ
3
=1-
λ
1
-
λ
2
In[]:=

Turning Barycentric Coordinates into Cartesian coordinates

We will convert the barycentric coordinates (2,7,1). I am using the digits of  as the example values by the way.
The triangle vectors will be:
r
1
=(8,1)​​
r
2
=(8,2)​​
r
3
=(4,5)
Set up the numbers
In[]:=
barycentricCoordinates={2,7,1};​​r1={8,1};​​r2={8,2};​​r3={4,5};
We can convert this to Cartesian coordinates with the dot product
x=
λ
1
x
1
+
λ
2
x
2
+
λ
3
x
3
=(
λ
1
,
λ
2
,
λ
3
).(
x
1
,
x
2
,
x
3
)
y=
λ
1
y
1
+
λ
2
y
2
+
λ
3
y
3
=(
λ
1
,
λ
2
,
λ
3
).(
y
1
,
y
2
,
y
3
)
Evaluate the Cartesian coordinate with the dot product
In[]:=
x=barycentricCoordinates.{r1,r2,r3}[[All,1]]
Out[]=
76
In[]:=
y=barycentricCoordinates.{r1,r2,r3}[[All,2]]
Out[]=
21
The Cartesian coordinates of the barycentric coordinates (2,7,1) in a triangle with vertex vectors at (8, 1), (8, 2), and (4,5) is 76 and 21.
In[]:=

Turning Cartesian coordinates into Barycentric Coordinates

We can find the inverse to double check our work
T=
x
1
-
x
3
x
2
-
x
3
y
1
-
y
3
y
2
-
y
3

This time we are going from (8,1), (8,2) and (4,5) and the Cartesian coordinates (76,21) to barycentric coordinates with an inverse matrix
We set the vector r to (x,y)
In[]:=
r={76,21};
In[]:=
MatrixFormT=
r1[[1]]-r3[[1]]
r2[[1]]-r3[[1]]
r1[[2]]-r3[[2]]
r2[[2]]-r3[[2]]

Out[]//MatrixForm=

4
4
-4
-3

We will use this to find
λ
1
and
λ
2
.
λ
1
λ
2
=
-1
T
(r-
r
3
)
In[]:=
{
λ
1
,
λ
2
}=Inverse[T].(r-r3);
λ
3
is related to
λ
1
and
λ
2
by the sum of weights which is unity or
λ
1
+
λ
2
+
λ
3
=1
. Therefore we can calculate
λ
3
with
1-
λ
1
-
λ
2
In[]:=
λ
3
=1-
λ
1
-
λ
2
;
We can now display the three barycentric coordinates
In[]:=
MatrixForm
λ
1
λ
2
λ
3

Out[]//MatrixForm=
-70
88
-17
We can double check our work with the dot product.
In[]:=
{
λ
1
,
λ
2
,
λ
3
}.{r1,r2,r3}[[All,1]]​​{
λ
1
,
λ
2
,
λ
3
}.{r1,r2,r3}[[All,2]]​​{
λ
1
,
λ
2
,
λ
3
}.{r1,r2,r3}[[All,1]]==r[[1]]​​{
λ
1
,
λ
2
,
λ
3
}.{r1,r2,r3}[[All,2]]==r[[2]]
Out[]=
76
Out[]=
21
Out[]=
True
Out[]=
True
In[]:=

Using the explicit relationship

Explicitly, the formulae for the barycentric coordinates of point r in terms of its Cartesian coordinates
(x,y)
and in terms of the Cartesian coordinates of the triangles vertices are:
λ
1
=
(
y
2
-
y
3
)(x-
x
3
)+(
x
3
-
y
3
)
det(T)
=
(
y
2
-
y
3
)(x-
x
3
)+(
x
3
-
x
2
)(y-
y
3
)
(
y
2
-
y
3
)(
x
1
-
x
3
)+(
x
3
-
x
2
)(
y
1
-
y
3
)
λ
2
=
(
y
3
-
y
1
)(x-
x
3
)+(
x
1-
x
3
)(y-
y
3
)
det(T)
=
(
y
3
-
y
1
)(x-
x
3
)+(
x
1-
x
3
)(y-
y
3
)
(
y
2
-
y
3
)(
x
1
-
x
3
)+(
x
3
-
x
2
)(
y
1
-
y
3
)
λ
3
=1-
λ
1
-
λ
2
In[]:=
ToPlanarBarycentricCoordinatesExplicit[cartesian_List,vecs_List]:=Module{x1,x2,x3,y1,y2,y3,x,y,λ1,λ2,λ3},x=cartesian[[1]];y=cartesian[[2]];x1=vecs[[1,1]];y1=vecs[[1,2]];x2=vecs[[2,1]];y2=vecs[[2,2]];x3=vecs[[3,1]];y3=vecs[[3,2]];λ1=
(y2-y3)(x-x3)+(x3-x2)(y-y3)
(y2-y3)(x1-x3)+(x3-x2)(y1-y3)
;λ2=
(y3-y1)(x-x3)+(x1-x3)(y-y3)
(y2-y3)(x1-x3)+(x3-x2)(y1-y3)
;λ3=1-λ1-λ2;{λ1,λ2,λ3}/;Dimensions[vecs]=={3,2}
In[]:=
ToPlanarBarycentricCoordinatesExplicit[{76,21},{{8,1},{8,2},{4,5}}]
Out[]=
{-70,88,-17}
There is also a Resource Function BarycentricCoordinates that includes generalized barycentric coordinates (see below)
In[]:=
PersistResourceFunction["BarycentricCoordinates"]
Out[]=
Success
✓
Message: Successfully stored BarycentricCoordinates as an initialization symbol.
PersistenceLocation: PersistenceLocation
Type: Local


In[]:=

Vertex Approach

Another way to solve the conversion from Cartesian to barycentric coordinates is to write the relation in the matrix form
Rλ=r
which is
where
is twice the signed area of the triangle. The area interpretation of the barycentric coordinates can be recovered by applying Cramer's rule to this linear system.

Applications

In[]:=

Determining location with respect to a triangle

Summarizing,
Otherwise r lies outside the triangle
In particular, if a point lies on the opposite side of a sideline from the vertex opposite that sideline, then that point's barycentric coordinate corresponding to that vertex is negative.
I will design a function that displays a string indicating where a triangle point is with relation to the triangle.
In[]:=

Interpolation on a triangular unstructured grid

These methods have many applications, such as the finite element method (FEM).
In[]:=

Integration over a triangle or tetrahedron

Examples of special points

The three vertices of a triangle have barycentric coordinates 1:0:0, 0:1:0, and 0:0:1.
The centroid has barycentrics 1/3:1/3:1/3.
The circumcenter of a triangle ABC has barycentric coordinates
The orthocenter has barycentric coordinates
The incenter has barycentric coordinates
The excenter's barycentrics are
The nine-point center has barycentric coordinates

Generalized Centroid

If two dimensional barycentric coordinates for a simplex's centroid (a triangle in a two dimensional plane) is 1/3:1/3:1/3 then a higher dimensional centroid of a simplex could be 1/n+1:1/n+1:…:1/n+1:1/n+1 n+1 times.
A 4 dimensional centroid

Triangle Centers

In[]:=

Centroid

Verifying the centroid's barycentric coordinates are 1/3:1/3:1/3
Verifying the centroid in barycentric coordinates symbolically
Make a geometric scene for the centroid. The centroid is the intersection of the a line from each vertex to the midpoint of the opposite side named the median.
In[]:=

Orthocenter

Find the orthocenter of the triangle example.
In this case the scale factor without normalizing the barycentric coordinates for the orthocenter is 64.
Calculate the scaling value symbolically to normalize the orthocenter's barycentric coordinates.
Scale the barycentric coordinates of the orthocenter by the sum to obtain normalized barycentric coordinates and convert to the orthocenter's Cartesian coordinates
This is the symbolic output in Cartesian coordinates.
Make a geometric scene for the orthocenter. The orthocenter is the intersection of the altitudes which are lines that pass through a vertex and are perpendicular to the opposite side.

Barycentric coordinates

This is again a linear transformation, and we may extend the above procedure for triangles to find the barycentric coordinates of a point r with respect to a tetrahedron.
where T is now a 3x3 matrix:
Once again, the problem of finding the barycentric coordinates has been reduced to inverting a 3x3 matrix.
3D barycentric coordinates may be used to decide if a point lies inside a tetrahedral volume, and to interpolate a function within a tetrahedral mesh, in an analogous manner to the 2D procedure. Tetrahedral meshes are often used in finite element analysis because the use of barycentric coordinates can greatly simplify 3D interpolation.

Generalized barycentric coordinates

is undetermined. The simplest example is a quadrilateral in the plane. Various kinds of additional restrictions can be used to define unique barycentric coordinates.
In[]:=

Abstraction

Applications

Generalized barycentric coordinates have applications in computer graphics and more specifically in geometric modeling. Often a three dimensional model can be approximated by a polyhedron such that the generalized barycentric coordinates with respect to that polyhedron have a geometric meaning. In this way, the processing of the model can be simplified by using meaningful coordinates. Barycentric coordinates are also used in geophysics.