ABC is a triangle. R is a point inside that triangle, specified by its barycentric coordinates. w is a scalar.
We mark the points B' and C' such that
- BB' == w and AB' == AB - w
- CC' == w and AC' == AC - w
My question is, given the three triangle sides, w and the barycentric coordinates of the point R, is there a way to determine if the point lies inside the subtriangle AB'C' or outside of it?
What I did so far is:
M = [A, B, C]
(each point is specified in a 3D space, so the matrix is of size 3x3)
The points of the inner triangle are A, B' and C', which I can also express in a matrix form:
[A, B', C'] = M * K
where K =
[1, p, q
0, 1-p, 0,
0, 0, 1-q]
p = w / AB
q = w / AC
I already know the barycentric coordinates of R, which I denote Rb below.
Thus M * Rb == M * K * Xb
Where Xb is a 3x1 vector holding the barycentric coordinates of the same point, expressed in terms of the inner triangle AB'C'.
Sadly, while K is invertible, M is not, thus I cannot express Xb as K^-1 * Rb.
Am I heading in the right direction or is there another/better solution (if there is a solution at all)?
One basic approach to check if a point is inside a triangle is what's called the dot-product method (the third method described here). However this method relies somewhat on you having a right oriented coordinate system in two dimensions, but with barycentric coordinates we have three coordinates.
Now if we assume that we require the barycentric coordinates to add up to $1$ we would write the coordinates of a point $R$ as $R$ = $r_aA+r_bB+r_cC$ (avoiding having to divide by $r_a+r_b+r_c$ as required otherwise). This is awfully much like a normal coordinate system in three dimensions, and the requirement that the barycentric coordinates to add up to $1$ is the equation of a plane.
To mimic the dot-product method we need to construct a vector perpendicular to the oriented edges, but for a plane given in this form we know that we can form such a vector by forming the vector product with the normal to the plane. If $A$, $B$ and $C$ was an orthogonal base we would use the normal formula. However the fact that $R$ is inside the triangle is invariant under linear mapping - that is we can use the same formula anyway.
Now for a vector $(x,y,z)$ in that plane we form that normal by vector multiplying with a normal $(1,1,1)$ to the plane. That is
$$(x,y,z)\times(1,1,1) = (y-z , z-x , x-y)$$
So you use this to form the normals to $\overline{AB'}$, $\overline{B'C'}$ and $\overline{C'A}$ and then take the dot product of these with $\overline{AR}$, $\overline{B'R} and $\overline{C,R}$ respectively.
(note that when subtracting two points as in $\overline{AB'}$ you get a tripple, but these are not the barycentric coordinates for any point).