Test if point in 3D is above triangle using vertex normals

105 Views Asked by At

Please, my problem is very close to Find a point on triangle and interpolated triangle normal which points to specific point in 3D, but I do not need to find analytical/numerical solution. I rather just need to find out if solution exists, i.e. whether the specific point in 3D is above the triangle or not. (Still please see the linked question for context.)

I realized that by using cross product I can eliminate the $k$ from there, as the interpolated normal $A$ and the vector $B$ towards the point $p$ should be collinear in case the point $p$ is above the triangle. So I have this cross-product equation: $$ A \times B = 0 $$ where $$ A = b_1n_1+b_2n_2+(1-b_1-b_2)n_3 \\ B = p-b_1v_1-b_2v_2-(1-b_1-b_2)v_3 $$

Here I got stuck as I do not know what might be a next step to solve my problem. I have 1 equation and 2 unknown $b_1$ and $b_2$. Please could somebody help me?

1

There are 1 best solutions below

2
On

Triangles are planar figures. The three vertexes determine a unique plane, and as the sides of the the triangle are line segments connecting points in that plane, they all lie in the plane as well. As such, there is only a single normal. It does not change as you move from point to point. Thus the normal vectors $\mathbf n_1, \mathbf n_2,\mathbf n_3$ are all the same vector (I am assuming they are all vectors of unit length, though the other post does not say so).

And so $$\mathbf A = b_1\mathbf n + b_2\mathbf n + (1 - b_1 - b_2)\mathbf n = \mathbf n$$ And your equation is $$\mathbf n \times \mathbf B = 0$$ $\mathbf n$ itself is found by dividing $(\mathbf v_1 - \mathbf v_3)\times (\mathbf v_2 - \mathbf v_3)$ by its norm.

The next matter is that you've forgotten this is a vector equation, not a scalar equation. In fact, that vector equation is three separate scalar equations grouped together. You don't have one equation in two unknowns. you've got three equations in two unknowns. For convenience, calling the barycentric coordinats $(s,t)$ instead of $(b_1, b_2)$, we get:

$$\mathbf n \times \mathbf p - s\mathbf n \times \mathbf v_1 - t \mathbf n \times \mathbf v_2 - (1 - s - t)\mathbf n \times \mathbf v_3 = 0$$ If we set $$\mathbf P =\mathbf n \times \mathbf p\\\mathbf V_1 = \mathbf n \times \mathbf v_1\\\mathbf V_2 = \mathbf n \times \mathbf v_2\\\mathbf V_3 = \mathbf n \times \mathbf v_3$$ Then $$P_x - V_{3x} = s(V_{1x} - V_{3x}) + t(V_{2x} - V_{3x})\\ P_y - V_{3y} = s(V_{1y} - V_{3y}) + t(V_{2y} - V_{3y})\\ P_z - V_{3z} = s(V_{1z} - V_{3z}) + t(V_{2z} - V_{3z})$$ Fortunately, these equations are not independent, so it will have solutions. If you started with a true triangle (i.e., $\mathbf v_1, \mathbf v_2, \mathbf v_3$ are not collinear), the solution will be unique.