# Chapter 5: Barycentric Coordinates

We’re going to use triangles a lot this quarter. So we need a way to figure things out about triangles. One thing we’re definitely going to test is whether certain points are inside a triangle or not, but we’ll also need to answer other questions, like what color a part of a triangle is.

The idea behind Barycentric Coordinates is that we’re going to use three numbers to describe the position of a point in relation to a specific triangle. These numbers represent more or less the “closeness” to each vertex - if a point is really close to vertex A of a triangle and far from B and C, we would say that the barycentric coordinates of the point are, say, 98% A, 1% B, and 1% C.

## Basics

Barycentric coordinates of point $p$ in terms of $a$, $b$, and $c$ are the numbers $\alpha$, $\beta$, and $\gamma$ such that:

With the constraint:

This must be true if the three values are barycentric coordinates.

However, the values don’t have to be positive.

A point $p$ is inside the the triangle if and only if:

What does $\alpha = 0$ mean? Any point opposite the vertex $a$, or rather along the line from $b$ to $c$.

What about $\alpha, \beta = 0$? In this case we know $\gamma$ must be $1$, this is the $c$ vertex.

The center of the triangle is $\alpha = \beta = \gamma = \frac{1}{3}$

## Cartesian to Barycentric

Barycentric coordinates are a ratio of areas.

Where the total area of the triangle is simply $A$, and each of the points is:

Given these areas, we can compute the Barycentric coordinates:

We can compute these areas using a 2D cross product*.

*Note: There is technically no such thing as a 2D cross product. But we will revisit cross products in a couple of weeks, and the formulas are useful to use here.

The cross product gives the area of a parallelogram formed by two vectors, so for the area of a given triangle we want $\frac{1}{2}$ of the cross product.

Be careful: The choice of both which edges to use and the order to use them is very important! There are many possible correct choices, but there are also many possible incorrect ones. Use the values I have below to avoid confusion.

To compute the total area $A$ as:

To compute the small triangle area $A_b$ as:

To compute the small triangle area $A_c$ as:

Computing the determinants is left as exercise for the reader :-)

Except I’ll share the solution for A here:

Finally, we can compute $\alpha$ from $\beta$ and $\gamma$:

## Area Example

Thank you to Dr. Zoe Wood for the above Processing example!

## Interpolation

Now we can use $\alpha, \beta, \gamma$ to interpolate colors and depth of the triangle.

In general the barycentric coordinates can be used to interpolate anything across the triangle. For vertex colors, we will specify $r, g, b$ values for each point to represent the red, green, and blue values of each vertex.

To interpolate these colors values across the triangle, we must interpolate each “channel” individually.