<p>Thats the way your defining the vectors. See your defining vectors $V_1$ and $V_2$ as pointing outwards from the point $P_2$.</p>

<p><a href="https://i.sstatic.net/DhmzX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/DhmzX.png" alt="enter image description here"></a></p>

<p>Now then $denom$ is the square of the area of the parallelogram of formed by completing the triangle with a duplicate of itself. Another way to look at this is that its the 2 tines the square of the are of the triangle.</p>

<p><a href="https://i.sstatic.net/C7Rsq.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/C7Rsq.png" alt="enter image description here"></a></p>

<p>Now then the calculation:</p>

<pre><code>(d11 * d20 - d01 * d21)
</code></pre>

<p>Is the square area of the parallelogram of $P_2$-$T$-$P_3$</p>

<p><a href="https://i.sstatic.net/ErNBM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ErNBM.png" alt="enter image description here"></a></p>

<p>Now if you divide this with denom, then you have calculated the total area relative area of triangle $P_2$-$T$-$P_3$. So the formula <code>(d11 * d20 - d01 * d21) / denom</code> is the triangle size in relation to whole triangle size of: </p>

<p><a href="https://i.sstatic.net/napil.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/napil.png" alt="enter image description here"></a></p>

<p>This is the weight that the opposing corner exerts on the point. which in other words it is the barycenter weight related to point $P_1$.</p>

<p>The next line is simply the relative area of triangle $P_2$-$T$-$P_1$ or:</p>

<p><a href="https://i.sstatic.net/YYu3U.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YYu3U.png" alt="enter image description here"></a></p>

<p>Which is opposite to $P_3$ being the barycentric coordinate of $P_3$.</p>

<p>Lastly you calculate the rest which is the remaining triangle which is opposite of $P_2$ using <code>1 - bary[0] - bary[1]</code>.</p>

<p><strong>Note</strong>: You could have chosen the first vectors differently for a different order.</p>

CC BY-SA 3.0
2017-04-20T05:04:12.603Z
Awesome, I'm looking for this kind of explanation. BTW, there is small mistake, the $V_1$ should be $V_0$, $V_2$ should be $V_1$ and $V_3$ should the vector pointing to $T$. Hopefully you have the time to fix that error. Thanks once again, hopefully many people benefit from this.
Bla...
CC BY-SA 3.0
2017-04-20T05:34:08.433Z
Argh, @Bla... yes i will redraw the pictures. Anyway i am feeling that the variables in the code could have more understandable names. $V_0$ - $V_2$ offcourse being reasonable names but would be much better to name them with same nomenclature as your points.
joojaa
CC BY-SA 3.0
2017-04-20T06:32:07.133Z
I just changed the variable names, hopefully now it becomes clearer.
Bla...
CC BY-SA 3.0
2017-04-19T14:56:08.043Z
2017-04-20T05:27:32.077Z
2017-04-20T05:27:32.077Z
joojaa
<p>You can find which coefficient belongs to which vertex empirically by changing <code>t</code> to be one of the points on the triangle (<code>p1, p2, p3</code>). Then one of the coefficients will be <code>1</code> and others are <code>0</code>. Based on that you know which coefficient belongs to which vertex. Then, interpolating the normal is trivial:</p>

<pre><code>interpolatedNormal = bary[0] * p1_normal + bary[2] * p2_normal + bary[1] * p3_normal;
</code></pre>

<p>But I'm still curious the mathematical explanation behind this.</p>

CC BY-SA 3.0
2017-04-19T02:08:11.633Z
2017-04-19T02:08:11.633Z
Bla...
<p>Given a triangle and a point inside the triangle in Cartesian coordinate system, I compute the Barycentric coordinate of the point like this:</p>

<pre><code>double v2_1[3], v2_3[3], v2_t[3];

double bary[3];
vtkMath::Subtract(p1, p2, v2_1);
vtkMath::Subtract(p3, p2, v2_3);
vtkMath::Subtract(t, p2, v2_t);

float d00 = vtkMath::Dot(v2_1, v2_1);
float d01 = vtkMath::Dot(v2_1, v2_3);
float d11 = vtkMath::Dot(v2_3, v2_3);
float denom = d00 * d11 - d01 * d01;

float d20 = vtkMath::Dot(v2_t, v2_1);
float d21 = vtkMath::Dot(v2_t, v2_3);
bary[0] = (d11 * d20 - d01 * d21) / denom;
bary[1] = (d00 * d21 - d01 * d20) / denom;
bary[2] = 1.0f - bary[0] - bary[1];

return bary;
</code></pre>

<p>Now, how can I use the values in <code>bary</code> to interpolate the vertex normal at <code>p1</code>, <code>p2</code> and <code>p3</code>? Specifically, I'm confused which coefficient belongs to which vertex.</p>

CC BY-SA 3.0
2017-04-18T08:04:32.533Z
try some values, the coefficient that is near 1 when the point inside is close to a vertex belongs to that vertex.
ratchet freak
CC BY-SA 3.0
2017-04-18T09:01:48.193Z
@ratchetfreak I did that, but I'm also curious how to mathematically find the respective coefficient.
Bla...
<interpolation>
How do I use barycentric coordinates to interpolate vertex normal?
Bla...
# How do I use barycentric coordinates to interpolate vertex normal?

(Asked by: username_0 on 2017-04-18)

Given a triangle and a point inside the triangle in Cartesian coordinate system, I compute the Barycentric coordinate of the point like this:

```
double v2_1[3], v2_3[3], v2_t[3];

double bary[3];
vtkMath::Subtract(p1, p2, v2_1);
vtkMath::Subtract(p3, p2, v2_3);
vtkMath::Subtract(t, p2, v2_t);

float d00 = vtkMath::Dot(v2_1, v2_1);
float d01 = vtkMath::Dot(v2_1, v2_3);
float d11 = vtkMath::Dot(v2_3, v2_3);
float denom = d00 * d11 - d01 * d01;

float d20 = vtkMath::Dot(v2_t, v2_1);
float d21 = vtkMath::Dot(v2_t, v2_3);
bary[0] = (d11 * d20 - d01 * d21) / denom;
bary[1] = (d00 * d21 - d01 * d20) / denom;
bary[2] = 1.0f - bary[0] - bary[1];

return bary;

```

Now, how can I use the values in `bary` to interpolate the vertex normal at `p1`, `p2` and `p3`? Specifically, I'm confused which coefficient belongs to which vertex.

**Tags:** interpolation

> **Comments:**
> **username_1**: try some values, the coefficient that is near 1 when the point inside is close to a vertex belongs to that vertex.  
> **username_0**: @username_1 I did that, but I'm also curious how to mathematically find the respective coefficient.  

---

## 2 answers

### Answer by username_2 on 2017-04-19. Score: 7 | Accepted answer

Thats the way your defining the vectors. See your defining vectors $V\_1$ and $V\_2$ as pointing outwards from the point $P\_2$.

[![enter image description here](https://i.sstatic.net/DhmzX.png)](https://i.sstatic.net/DhmzX.png)

Now then $denom$ is the square of the area of the parallelogram of formed by completing the triangle with a duplicate of itself. Another way to look at this is that its the 2 tines the square of the are of the triangle.

[![enter image description here](https://i.sstatic.net/C7Rsq.png)](https://i.sstatic.net/C7Rsq.png)

Now then the calculation:

```
(d11 * d20 - d01 * d21)

```

Is the square area of the parallelogram of $P\_2$-$T$-$P\_3$

[![enter image description here](https://i.sstatic.net/ErNBM.png)](https://i.sstatic.net/ErNBM.png)

Now if you divide this with denom, then you have calculated the total area relative area of triangle $P\_2$-$T$-$P\_3$. So the formula `(d11 * d20 - d01 * d21) / denom` is the triangle size in relation to whole triangle size of:

[![enter image description here](https://i.sstatic.net/napil.png)](https://i.sstatic.net/napil.png)

This is the weight that the opposing corner exerts on the point. which in other words it is the barycenter weight related to point $P\_1$.

The next line is simply the relative area of triangle $P\_2$-$T$-$P\_1$ or:

[![enter image description here](https://i.sstatic.net/YYu3U.png)](https://i.sstatic.net/YYu3U.png)

Which is opposite to $P\_3$ being the barycentric coordinate of $P\_3$.

Lastly you calculate the rest which is the remaining triangle which is opposite of $P\_2$ using `1 - bary[0] - bary[1]`.

**Note**: You could have chosen the first vectors differently for a different order.

> **Comments:**
> **username_0**: Awesome, I'm looking for this kind of explanation. BTW, there is small mistake, the $V_1$ should be $V_0$, $V_2$ should be $V_1$ and $V_3$ should the vector pointing to $T$. Hopefully you have the time to fix that error. Thanks once again, hopefully many people benefit from this.  
> **username_2**: Argh, @Bla... yes i will redraw the pictures. Anyway i am feeling that the variables in the code could have more understandable names. $V_0$ - $V_2$ offcourse being reasonable names but would be much better to name them with same nomenclature as your points.  
> **username_0**: I just changed the variable names, hopefully now it becomes clearer.  

---

### Answer by username_0 on 2017-04-19. Score: 2

You can find which coefficient belongs to which vertex empirically by changing `t` to be one of the points on the triangle (`p1, p2, p3`). Then one of the coefficients will be `1` and others are `0`. Based on that you know which coefficient belongs to which vertex. Then, interpolating the normal is trivial:

```
interpolatedNormal = bary[0] * p1_normal + bary[2] * p2_normal + bary[1] * p3_normal;

```

But I'm still curious the mathematical explanation behind this.


---

