Clarificaiton on barycentric coordinates

2.1k Views Asked by At

This is related to ray tracing (which I learnt and then forgot).

Given a triangle in 3D $\widehat{ABC}$, where $A,B,C$ are the points of the triangle

And a parametric line described by $(O,\vec v)$ (origin and direction vector)

We find the point $P$ as the intersection of the line and the plane described by the triangle.

From here I become confused. The barycentric coordinates are basically the "normalized" areas of the triangles formed by taking $P$ and 2 of the vertices of the triangle. However this definition only makes sense when $P$ is inside of the triangle, when it's outside it stands that at least one of the coordinates must be negative.

My confusion comes when trying to understand how and why one of the 3 coordinates becomes negative when calculating the barycentric coordinates.

The formal definition tells us that $P=u*A+v*B+w*C$

Or that $P$ is a weighted sum of the vertices of the triangle such that $u+v+w=1$

When $P$ is inside the triangle each weight can be simply described as

$\frac{\widehat{PXY}}{XYZ}$ where $(X,Y,Z)$ represents any permutation of $(A,B,C)$

But off course this cannot be the case when $P$ is outside the triagle as at least one of the areas must be negative.

How are $u,v,w$ calculated exactly? I am not looking so much for a formal answer, but rather I want to understand the intuition behind the weight calculation.

2

There are 2 best solutions below

0
On BEST ANSWER

The word barycentric literally means “weight-centered.” The barycentric coordinates of a point relative to a polygon are the masses that you’d have to place at the vertices of the polygon for its center of mass to be at that point. Approaching it from the other direction, the point represented by the triangular barycentric coordinates $m_A:m_B:m_C$ is the center of mass of three point masses $m_A,m_B,m_C\gt0$ placed at the points $A$, $B$ and $C$, respectively, thus the formula for conversion of (unnormalized) barycentric to Cartesian coordinates: $${m_AA+m_BB+m_CC \over m_A+m_B+m_C}$$ literally a weighted average of the vertices. Relative to a triangle, these coordinates are proportional to the areas of certain triangles, which is the definition that you’ve learned.

For the triangle to balance along an edge, say $\overline{AB}$, there must be no mass at vertex $C$, so this physical model of barycentric coordinates extends easily to zero values. Negative coordinates are a bit trickier to interpret as masses, since (tantalizing ideas in physics notwithstanding), we don’t have negative mass. N.Bach’s model in another answer of attractors/repulsors at the vertices is a nice way to work negative coordinates into a mental image. In terms of masses, you can think of a negative barycentric coordinate as the amount you’d have to remove to shift the center of mass to the point or as describing having to place the mass on the opposite side of the point from the vertex to balance the masses there.

0
On

The intuition depends on the method you use to perform the computation. If you're comfortable with algebraic areas, I'm pretty sure you can still interpret negative coefficients as (algebraic) areas of the appropriate triangles. Note that in that case, you have to be careful with the permutation you use, since $\text{area}(ABC)=-\text{area}(ACB)$.

Technically, the sign of the coefficient mostly indicates if the specific point ($A,B$ or $C$) attracts or repulses $P$. If you are doing the computation manually, you can then easily deduce the appropriate sign. Since you tagged algorithms I guess you'd rather have a systematic interpretation though.


Another way to look at barycentric coordinates is to notice that any two sides of triangle $ABC$ defines a (most likely non-orthonormal) basis. This interpretation however breaks symmetry between the three points. For instance you can take $A$ as origin with basis vectors $\vec{AB}$ and $\vec{AC}$. \begin{align} \vec{AP} &= P-A=uA+vB+wC-(u+v+w)A\\ &=v\vec{AB}+w\vec{AC} \end{align} Then coefficients $v$ and $w$ are simply the coordinates of $P$ in the coordinate system $\left(A,\vec{AB},\vec{AC}\right)$. You can retrieve $u$ with $u=1-v-w$.

With this, it's not too difficult to see when a given coefficient will be negative. For instance take $v$, it will be :

  • zero when $P$ is on line $AC$
  • positive when $P$ and $B$ are on the same side of line $AC$
  • negative when $P$ and $B$ are on distinct sides of line $AC$

This also nicely ties in with the repulsion/attraction interpretation of barycentric coefficients. When $v$ is zero, you don't need $B$ to express $P$. When $v$ is positive, it pulls $P$ away from line $AC$, towards point $B$. When $v$ is negative, it pushes $P$ away from both line $AC$ and $B$.