# finding if a point is inside a cube all with XYZ coordinates

This topic is 2892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. I've been searching the web helplessly fo a while, and found this forum. I read a little and the people here seem to might have the answer to my problem.
I need to write a code to find out if a point is inside a rectangular shaped volume. The point will have an XYZ coordinates in space, and the volume of 8 corners each has XYZ coordinates. Can anyone help. The code that I am writing will be in Excel, so any help will be welcome, equations, VBA..anything.

Thanks

##### Share on other sites
Well, the one-dimensional check would consist of evaluating whether point's x is greater than the minimum x of the box AND less than the maximum x of the box.

It is fairly trivial to extend this logic to three dimensions.

---

Note that "rectangular" is a very strict definition of an area in which the adjoining sides are perfectly perpendicular to each other, and opposite sides are of exactly equal length; therefore, in this special case, the calculations are easy to reduce to simple comparisons of coordinates.

However, if the xyz coordinates of the corners are allowed to be arbitrary (hence not necessarily rectangular faces in any space), you need to take a more robust approach like constructing planes from all the corners and checking whether the point satisfies the "insideness" constraint against all of said planes (for example).

##### Share on other sites

Did you try to solve this by yourself?

I mean .. if you draw a picture on the paper with rectangular shape and point you'd discover soon the required conditions for testing point-inside-rectangular-shape.

Anyway, to give you some hint, you can define your rectangular volume by it's minimum and maximum extends ie. two XYZ-coordinates.

To test if the point is inside the volume, for each axis you can check if the point is between the minimum and maximum coordinates of that axis. Ie. if(Point.x >= Box.Min.x && Point.x <= Box.Max.x), repeat that for each axis and if any of the tests fail the point is outside.

Good luck!

##### Share on other sites
Thank you all for the quick reply. Yes I did try to solve the problem. I try to simplified it but the problem is that I am working with a rectangular "volume" in space with 8 corner each with a different XYZ. The volume can, therefore, be tileted, or rotated. So even though the X-coordinate of the point in question is greater than the minX and smaller than the maxX, the grid rotation or tilting can cause the point of XYZ to fall outside the cube or volume.

##### Share on other sites
You'll need to know the transformation for your bounding box, i.e., the matrix that rotates/tilts your box. You'll also need the min/max coordinates for the bounding box in the bounding box's local space. Apply the transformation to the world coordinates you want to test. Compare the result to the local min/max coordinates to determine if the converted coordinates are within the local bounds.

##### Share on other sites
There's yet another way. Imagine the sides of the box are pointing outwards, i.e. the side out can see is the front and the side you can't see is the back. Now when is the point in the box? Right, when it's on the back of all sides. How to compute on which side the point is on is a pretty common problem, just google for "point plane distance". That will work not only for boxes but also for any convex object.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013221
×