You can find the equation that represents the surface by applying the 3 points to the following:
ax+by+cz+d = 0
after you found a,b and c you have the surface - so the first thing would be to check if point P is on the surface. If it is, we still have to check that it's on the triangle.
For that we'll create a diagonal line, that goes through P, to each one of the edges, or to be more exact, to the linear equation which "includes" the edges (please excuse my poor English - I learned this stuff in my native language so bear with me).
This can be done by taking each pair of points (from the triangle), say A=(x1,y1,z1)
and B=(x2,y2,z2)
and assigning them to the first equation. we'll get a linear equation:
y = mx + n
.
Here m
is the incline
- so the diagonal equation will have
m' = -1/m
and since we know the values of P
we can use both to find the value of n
.
Now that we have both equations we can find the point that exists on both lines. Let's call this point P'.
It's easy to find if P' is between A
and B
. if it is (for every pair!) - then P is inside the triangle, else, it's not.
Example:
