Monday, 24 December 2012

Barycentric Coordinates

Hi,

This article mainly concentrates on showing what Barycentric coordinates are, and how they are used in Computer Graphics.

Consider the following example:(This can also apply to lines)


Now, Barycentric coordinates allow us to express any point within this triangle in terms of the Vertices (P1, P2, P3). Let's see how this can be done.

Now, starting from P1, we can easily say that
P = P1 + (a)*(vector from P1 to P2) + (b)*(vector from P1 to P3)

Now, this is the same as:
P = P1 + a(P2 - P1) + b(P3 - P1)

Now, this can be written as:
P = (1 - a - b)P1 + aP2 + bP3

Now, let (1 - a - b) = c

Thus, we get:

P = c(P1) + b(P3 - P1) + a(P2 - P1)

Thus, any point within the triangle can be expressed via a combination of a, b, c! Also, we can see that:

a + b + c = 1   

So, we thus have a coordinate system(consisting of 3 numbers a, b, c) w.r.t to a triangle. This is called as a Barycentric coordinate system.

Now, let us see an example in Computer Graphics. Suppose we want to rasterize a triangle and assign pixel colors to each of the pixel within the triangle, provided we already have the per vertex colors with us, then we can use this concept to assign pixel values to all pixels in the triangle.

In that case, the points would actually be colors, instead of positions. But, the colors would be linearly interpolated across the triangle.