Given the triangle with vertices (a,b,c):
c / \ / \ / \ a - - - - b
Which is then subdivided into four triangles by halving each of the edges:
c / \ / \ ca / \ bc _ _ _ /\ /\ / \ / \ / \ / \ a - - - - ab - - - -b
Which results in four triangles (a, ab, ca), (b, bc, ab), (c, ca, bc), (ab, bc, ca).
Now given a point p. How do I determine in which triangle p lies, given that p is within the outer triangle (a, b, c)?
Currently I intend to use ab as the origin. Check whether it is to the left of right of the line "ca - ab" using the perp of "ca - ab" and checking the sign against the dot product of "ab - a" and the perp vector and the vector "p - ab". If it is the same or the dot product is zero then it must be in (a, ab, ca)... Continue with this procedure with the other outer triangles (b, ba, ab) & (c, ca, ba). In the end if it didn't match with these it must be contained within the inner triangle (ab, bc, ca).
Is there a better way to do it?
EDIT
Here is a little more info of the intended application of the algorithm:
I'm using this as a subdivision mask to generate a fine mesh over which I intend to interpolate. Each of the triangles will be subdivided similarly up to a specified depth. I want to determine the triangle (at the maximum depth) within which the point p lies. With this I can evaluate a function at the point p using interpolation over the triangle. There is a class of triangles which is right-angled and they do comprise a significant portion, but they're much easier to work with and this algorithm isn't intended for them.