I have an ordered list of 3D points P1, ..., Pn that compose the vertices of a polygon. It is NOT assumed that the polygon is planar.
I need to determine whether a 3D point P is contained in the polygon (either on one of the edges or inside). Is it mathematically correct to proceed as follows?
- Every sequence of 3 consecutive points Pi-1, Pi, Pi+1 define a planar triangle. I can use, e.g., the method described in Check whether a point is within a 3D Triangle to determine whether the point is in in the triangle.
- A point P is contained in the polygon if it is contained in one of the triangles composing the polygon.
Corollary questions: If the above method is correct
- Are there more efficient ways to compute this?
- Can the above method be used to compute the area of the polygon? In other words, is the area of the polygon equal to the sum of the areas of the composing triangles?
Theoretically, the term "non-planar polygon" itself is confusing since the word "polygon" already implies it is planar. I am going to assume that you actually meant that the polygon does not lie on the x-y plane but in the 3D space.
To check whether a 3D point lies in a planar polygon in the 3D space, the easiest way is to transform all polygon vertices and the 3D point to the coordinate system of the plane where the polygon lies. If the transformed 3D point still have a z value, then it is off the plane and will not be "contained" by the polygon. If the transformed 3D point lies on the plane, then you can check whether it lies within the polygon easily (see answer to this question)
BTW, your proposed method that checks whether the point lies in the triangle formed by 3 consecutive vertices of the polygon will not work when the polygon is non-convex.