# Lecture 3: 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 in terms of , , and are the numbers , , and 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 is inside the the triangle if and only if:

What does mean? Any point opposite the vertex , or rather along the line from to .

What about ? In this case we know must be , this is the vertex.

The center of the triangle is

## Cartesian to Barycentric

Barycentric coordinates are a ratio of areas.

Where the total area of the triangle is simply , 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 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 as:

To compute the small triangle area as:

To compute the small triangle area as:

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

Except I’ll share the solution for A here:

Finally, we can compute from and :

## Area Example

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

## Interpolation

Now we can use 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 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.