CG · Maths · Python

Barycentric Coordinates

Barycentric Coordinates is a type of coordinate system to define the coordinates of an entity in “n-dimensional space” (for CG it is 3 dimensions). One of the interesting properties of this coordinate system is that it is affine and depends on the object space.

Barycentric Coordinates were formulated  by Mobius (who is also known for the famous Mobius strip) in 1827.

This coordinate system bears significant importance especially in Computer Graphics but it can be a daunting task to understand fully the concept of Barycentric Coordinates for not so mathematically inclined.

So in this post, I will try to explain in the simplest terms, what Barycentric Coordinates are and how they are used in Computer Graphics.

As is the case with many other DCC Applications, Barycentric Coordinates are exploited to a great extent in Softimage. Although I have no official proof, but I can most safely say that the Location Data we so much love and use in ICE are nothing but an implementation of Barycentric Coordinates.

To begin with, Consider a triangle.

1

If I was asked to find a point on this piece so that it could be balanced perfectly on a point of a pencil, what would I do? A little bit of intuition would suggest taking the central point of the triangle.

2

That is all correct, but let’s now complicate things a little bit. If the shape of the piece is an irregular triangle with all sides having different lengths then the central point is not easier to guess.

3

I would solve this by applying a little geometry and divide each side in half and connect the opposite vertex of the triangle to these points. The lines thus created will yield the central point and I will be able to balance the triangle on that point with the pencil.

4

All good, now let us raise the bar some more and tie some weights to each vertex of the triangle. There are different weights on each vertex. Now the task of finding a point at which the triangle can be balanced is no more pure geometry. I have to consider that each of these weights is pulling the triangle with different forces.

5

This is where the Barycentric Coordinates can be applied to find the answer. In fact, the word barycentre originates from the Greek root “barus” which generally refers to weighty or heavy.

So to solve our problem we should divide each side of the triangle in the same ratio as the weights in the vertex forming that side, as shown below.

After getting this three points, it is just of matter of connecting this points to the opposite vertex and bingo! We have our balancing point:

6

 

What we just did was to find the Barycentric coordinates of the point with given weights at the vertices.

We can also write this as:

mathtex1

 

 

Where P is our barycentric point and A, B and C are the weights at the vertex. 10 comes from adding the three weights 2 + 3 + 5. Also, note that:

mathtex2

 

 

So now that we have the notion of barycenter, let us see how this relates to CG coordinates with vector geometry. We know that any triangle in the 3D Coordinate system can be defined as (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) representing the x, y,z-coordinates of each vertex. Also in vector notation, this can be written as, A, B, C where A, B and C are the vectors defining the point positions (vertices) of the triangle.

Let P be any arbitrary point on the triangle, then P can always be defined with the help of vectors A, B and C as :

mathtex3

Where,

mathtex4

Here ,

mathtex5

are called the Barycentric coordinates (remember these are just three real numbers for a triangle).

So now we totally understand the notion as well as the mathematical representation of Bary Centric Coordinates. How do we use it to make life easier in the CG World?

There are numerous ways to use them, but here I will discuss the locations in Softimage which are available both in ICE and the API methods.

The whole idea of locations magically following the mesh (or sticking to location) happens in the following way:

  1. First a point on the triangle is found which will be used as initial location. This can be done in many ways, raycasting is one of them. We throw a ray from a certain point, in a well defined direction towards the triangle. The point where the ray hits(intersects) with the triangle is determined.
  2. Once the coordinates(vector) of the point on the triangle is known, Barycentric coordinates this point are calculated (this calculation is not very hard, but still requires some mathematical knowledge, so I am skipping them for the purpose of being simple).
  3. Once we know the Barycentric coordinates for this point, we can simply get this point at any point of time just using the three position vectors of the triangle.
  4. In this way, even when the triangle is deformed in any way, we always know our point, in other words, the location of the point sticks to the triangle.
  5. For example, after doing a ray cast we find that barycentric coordinates for the location are (0.35, 0.25, 0.40). These will be fixed throughout the simulation/animation/mesh move. After the triangle has been transformed, to get our location, we have to simply get the vectors for the point position at this point and multiply them by the scalars 0.35, 0.25 and 0.40, add the result. This will give a new vector, which is our location.

This ICE Tree exhibits the barycentric coordinates in action. Even if you move the point of the triangle, the point will always lie in the triangle.

 

Download Scene File here. In the softimage scene, move the vertices of the triangle and you will see that the location represented by the red sphere will remain on the triangle:

8

 

I hope that now you have a better idea of what barycentric coordinates are.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s