I'm trying to calculate if a 2D point lies inside a triangle and I solved the following system:
| X_source | | x_first_vertex, x_second_vertex, x_third_vertex |
| Y_source | = [b0,b1,b2] * | y_first_vertex, y_second_vertex, y_third_vertex |
where b0,b1 and b2 are the barycentric coordinates I was searching for.
Now I'm wondering why, if the barycentric coordinates in wikipedia's picture here (http://en.wikipedia.org/wiki/File:TriangleBarycentricCoordinates.svg) have a 1 component when lying on a vertex, am I getting 0 for one of b0,b1,b2 when the vertex lies on an edge/vertex of the triangle..
The first vertex I obtained is: [ 0; 0.00000...17; 0.0500], and since it almost lies on the first vertex.. how come these three values don't yield 1 if I sum them together?
Where am I getting wrong with this?
You need to solve a little bit different system. Barycentric coordinates has to sum to the one. So you simply augment your system with one more equation
$$ \left( \begin{matrix} x_s \\ y_s \\ 1 \end{matrix} \right) = \left( \begin{matrix} x_1 & x_2 & x_3 \\ y_1 & y_2 & y_3 \\ 1 & 1 & 1 \end{matrix} \right) \left( \begin{matrix} b_0 \\ b_1 \\ b_3 \end{matrix} \right) $$
Your original system is $2\times 3$. You cannot expect unique solution with such a system, that is the reason why you didn't get one when you summed $b_i$.