If I have a square based pyramid of which I know every point (all 5), what is the algorithm to determine if a given point is inside that pyramid or not? I saw a similar question here Algorithm for checking if 3D point inside convex polyhedron (square pyramid) and here How to check whether the point is in the tetrahedron or not?. The answers given there did not really help and the math did not work out for me. I have seen approaches with creating a normal to each plane (4 triangles + 1 square) and checking on which side of the plane the point lies... however I do not know the correct math for that.
If someone could help me with the math/algorithm for that (preferably with explanation), it would really help.
Example Input:
# Pyarmid Points
A = np.array([2, 2, 4]) # pyramid top
B = np.array([1, 1, 1])
C = np.array([1, 3, 3])
D = np.array([3, 3, 1])
E = np.array([3, 1, 1])
# Example points
point_inside = np.array([2, 2, 2])
point_outside = np.array([3, 3, 3])
Example Expectation:
def check_point_in_pyramid(A, B, C, D, E, Point):
# math...
if point_inside_pyramid:
return true
return false
So for point_inside the function return would be true and for the point_outside it would be false.