0

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?

  • "... the interpolated normal $A$ and the vector $B$ towards the point $p$ should be collinear in case the point $p$ is above the triangle." The vector $B$ from where? If you mean the position vector of $p$ (the vector from the origin to $p$), the fact that $B$ is "collinear" with $A$ (which I'm taking to mean "parallel") tells you that $p$ is on a line through the origin perpendicular to the plane of the triangle. This line may or may not pass within the triangle, and there will certainly be points "above" the triangle that are not on this line. – David K Aug 19 '22 at 02:01
  • No, the vector B is meant from a point on triangle (let's mark it as x) to the point p. The point x can be computed again with barycentric coordinates as x = b1v1 + b2v2 + (1 - b1 - b2)v3. It is basically 'projection' of the point p onto the triangle in direction of normal (A) at that point. – Michal Wirth Aug 19 '22 at 08:44
  • And yes, by collinear I meant parallel. – Michal Wirth Aug 19 '22 at 09:14
  • Just to be clear, when you say "above" the triangle, I think you mean that an orthogonal projection from $p$ onto the plane of the triangle will project to a point inside the triangle. Is that a correct understanding of the question? – David K Aug 19 '22 at 12:23

1 Answers1

1

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.

Paul Sinclair
  • 43,643
  • Thank you for your answer. Unfortunately the normals n1, n2, n3 are not all the same. The problem comes from computer graphics where these normals are used for smooth shading of the triangle. They are usually different. If they would be all same, the problem would be easy as it could be even transformed by projection to 2D. – Michal Wirth Aug 19 '22 at 08:39
  • 1
    There are two issues with that statement. FIrst, it ignores that the second point of my answer still applies: You do not have 1 equation in 2 unknowns: you have 3 equations in 2 unknowns. Thus you have enough information to find a solution - provided that one exists (no longer guaranteed). The second issue is that you asked this in a math forum, not a computer graphics forum. In math, a "normal" vector is one perpendicular to a surface. A triangle can only have one normal. If you didn't mean normal in the mathematical sense, you should have made that clear in your post. – Paul Sinclair Aug 19 '22 at 11:49