The first conceptual step that will be useful is to determine if the point is in the same plane as the three points of your polygon that describe the plane. One way to do this is to compute the normal vector for the plane β name it n β and define the plane using n and one of the three points (name this point r 0 ).
The calculation of the normal vector for a plane can be performed in several ways (see here ). For this situation, the most convenient approach is the cross product between two vectors in the plane (find two vectors using points from the defining polygon).
Once you know n, you can check if the point r is in the plane with the point product between n and the vector (r 0 - r). See here for more details.
Then you can use orthogonal projection at any point to get a new point on the plane.
Example
Say I have three points:
- p 1 : [1, 1, 1]
- p 2 : [1.5, 6, 3]
- p 3 : [2, -1, 5].
First create a vector that is normal to the plane created by these points. Let be
- v 1 = p 1 - p 2 = [-0.5, -5, -2]
- v 2 = p 1 - p 3 = [-1, 2, -4].
Normal vector of these two then
- n = v 1 xv 2 = [24, 0, -6].
For convenience, we allow the normalization of n, so now n = [0.9701425, 0, -0.24253563].
Now we define a plane on n and let r 0 = p 1 .
Allows you to enter a new point r, which is not in the plane (you can check by taking the point product n and (r 0 - r):
One way to βmoveβ r to the plane is to βshiftβ it down the normal vector until it is on the plane (this is the orthogonal projection). This is done by determining which part of n is in the vector v 3 = (r 0 - r) (called the scalar projection ). The scalar projection in this case gives a new vector v 3m = [-0.88235294, -3, -3.52941176]. This computes v 3 - n * dot (n, v 3 ). You can check this on the plane because it is orthogonal to n.
Now we can restore the point:
- r m = r 0 - v 3m = [1.88235294, 4, 4.52941176].
You can check if this point is really in the plane:
- point (r 0 - r m , n) = 0.