Hello how are you?

I would like to know how do I know if that blue sphere is inside this abstract prism. I would like to know how to do this using only Unity coding, without using Colliders, Raycast or Colliders Trigger. There are 6 Vector3 (vertices). As you can see in the image, I wanted a function that returned a bool saying if the object is inside this prism or not. I’ve searched all over Google and haven’t found anything. I’ve tried bounds too, but apparently bounds act like a box, so sometimes the bool fails. If anyone can send me the solution I would appreciate it.

The objective is to know if an object is inside this 6-vertex prism (Vector3) without using Raycast or Collider. If it is inside it returns True, if it is outside it returns False.

Thanks! With your help other people will be able to see this topic. I believe this is the first post of its kind.

Can each face of the prism have an origin?

my initial thoughts are that we know where it cannot be, it cannot be greater than the furthest right, or less than the furthest left, it cannot be lower than the lowest point or higher than the highest point.

however using only the points shown this will make a cube of detection where it is at least 50% inaccurate: unless each face had an origin in its center.

so

we ask generically; is it between the corners (bounds)? And then if it is; well is it also between the center of origin of each face? Well yes it is:

will there be bugs? I don’t know.

-Corners of prism

centre of prism

-centre of face

Perhaps there is an easier method than the above that does not require a huge array of angular points and the working of a 3 dimensional grid.

If we want to keep it realistically computable, centre of face on left of origin, right of origin, centre of face up and down from origin .

I am certain we would ask each face individually, and they would be sorted from the prism center of origin. And so we would know that these faces are lower than prism origin and so we don’t want to be lower than them, these faces are right of center of origin so we don’t want to be greater than them. But the complexity of the prism I am sure would not scale. So perhaps if the prism was made of pentagon and hexagon, well then we would only ask for faces that are roughly the same longitude and latitude as us.

We would say where is our ball?

Oh it is X above center, and Y to the left, so which faces have this point in-between the range of points between their corners? Let us ask if we are between only the points of the face that align with the ball. In all directions.

If I am wrong maybe it inspires the correct answer.

Every prism has six vertices, but six vertices don’t necessarily make a valid prism.

You can define a prism like in your image as the convex volume created by five planes. Each edge is the line intersection between two planes and each vertex is the point intersection between two edge lines.

An infinite plane can be defined by a normal direction and a distance from the origin. With that data it’s possible to test if a point is in “front” or “behind” the plane. Any point that is behind all planes that make the convex prism is inside the prism.

Hi, thanks guys for the reply. My solution was to calculate the normal (using face center) of each face and apply an InverseTransformPoint(blueSphere) to that normal, take the Y of the calculated Inverse Point and check if the Y of all faces is greater than zero. Any questions about my solution?

- Calculate the normal of each face (using face center)
- Apply InverseTransformPoint(blueSphere) to face normal position (On Google there are formulas showing how to make an InverseTransformPoint without a transform)
- Check if Inverse Point Y is greater than 0 in all faces

1 Like