Home > Enterprise >  How can we check a point is within triangular pyramid?
How can we check a point is within triangular pyramid?

Time:11-05

We made a function returns a point is within triangle. Now we want to go further than that. We want to check a point is in the volume of tetrahedral pyramid or not with only coordinates. For example, our pyramid's coordinates is [(0, 0, 0), (3, 1, 4), (1, 4, 2), (6, 3, 5)]. And our target point is (1, 1, 0). It must return false. But if we made our point's Z is 1, it must return true.

CodePudding user response:

According to: Blackpawn

A common way to check if a point is in a triangle is to find the vectors connecting the point to each of the triangle's three vertices and sum the angles between those vectors. If the sum of the angles is 2*pi then the point is inside the triangle, otherwise it is not. It works, but it is very slow.

CodePudding user response:

One possible approach: calculate signed volumes of source tetrahedron and four tetrahedrons formed by point P and facets using the next determinants (I omit 1/6 factor).

All of them should be of the same sign for inside points

for source
      | x1  x2  x3  x4 |
V =   | y1  y2  y3  y4 |
      | z1  z2  z3  z4 |
      | 1   1   1   1  | 

      | px  x2  x3  x4 |
V1 =  | py  y2  y3  y4 |
      | pz  z2  z3  z4 |
      | 1   1   1   1  | 

      | x1  px  x3  x4 |
V2 =  | y1  py  y3  y4 |
      | z1  pz  z3  z4 |
      | 1   1   1   1  |

and similar for V3, V4 using P coordinates in corresponding column

  • Related