# Point in Triangular Prism (defined by plane)

## Recommended Posts

Phynix    129
How do I check if the projection of a point onto a plane is within a triangle on the plane, without actually projecting it?

In other words, how can I test to check if a point is contained in an infinite triangular prism protruding from a plane, given three points of the plane and the point to be tested:

I've tried something already, using the dot products of each vector, but it didn't seem to work...my code is below:

[script]

bool pointintrianglevolume(mlVertex P, mlTriangle t){
mlVertex vec1=t.p[0]-P;
mlVertex vec1a=P-t.p[1];
mlVertex vec2=t.p[1]-P;
mlVertex vec2a=P-t.p[2];
mlVertex vec3=t.p[2]-P;
mlVertex vec3a=P-t.p[0];
return (vec1.dot(vec1a)>=0&&vec2.dot(vec2a)>=0&&vec3.dot(vec3a)>=0);
}
[/script]

##### Share on other sites
Make sure your plane normals for the prism are all facing in the same direction and then use the dot product. If all dots return > 0 or < 0 they are all on one side of all the planes, and hence within the bounds of the prism. If they all return 0 you are in a dimension other than R3. There is another way that uses pluckers but pluckers you use a ray, not a point.