Jump to content
  • Advertisement
Sign in to follow this  
Need_ur_help

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!