This paper shows an elegant way to calculate barycentric coordinates ($w_1$ : $w_2$ : $w_3$) of a point $x_4$ with respect to a 3D triangle formed by three points $x_1$, $x_2$ and $x_3$ (given $\vec{x}_{ij} = \vec{x}_j - \vec{x}_i$):
$$ \begin{bmatrix} \vec{x}_{13} \cdot \vec{x}_{13} & \vec{x}_{13} \cdot \vec{x}_{23} \\ \vec{x}_{13} \cdot \vec{x}_{23} & \vec{x}_{23} \cdot \vec{x}_{23} \end{bmatrix} \begin{bmatrix} w_1 \\ w_2 \end{bmatrix} = \begin{bmatrix} \vec{x}_{13} \cdot \vec{x}_{43} \\ \vec{x}_{23} \cdot \vec{x}_{43} \end{bmatrix}\\ w_1 + w_2 + w_3 = 1 $$
Based on the barycentric coordinates definition:
$$ \vec{x}_{13} w_1 + \vec{x}_{23} w_2 = \vec{x}_{43} $$
So we can write this system of equations in the form of:
$$ (\vec{v} \cdot \vec{x}_{13}) w_1 + (\vec{v} \cdot \vec{x}_{23}) w_2 = (\vec{v} \cdot \vec{x}_{43}) $$
The nice thing about this system is that it works correctly even if the point $x_4$ doesn't lie on the triangle plane. However, there are 2 restrictions:
- $\vec{v}$ in different equations needs to be linearly independent.
- $\vec{v}$ needs to be perpendicular to the triangle normal, hence $\vec{x}_{13}$ and $\vec{x}_{23}$ are chosen for $\vec{v}$. I have tested other value of $\vec{v}$ that is not perpendicular to the triangle normal and the results are not correct.
The question: Why does $\vec{v}$ need to be perpendicular to the triangle normal?