Skip to main content
GameDev.net gamedev.net
🔒 Locked

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

Started by Need_ur_help Jan 7, 2011 at 6:24 AM 4 replies 20.1k views
Original Post
Need_ur_help
Need_ur_help
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
Nik02
Nik02
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).
Niko Suni
kauna
kauna

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!
Need_ur_help
Need_ur_help
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.
Buckeye
Buckeye
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.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
baw
baw
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.