Point within a Cube in 3D environment

995 Views Asked by At

I have a cube in 3D space with 8 corner points with their X,Y,Z Coordinates. I know how to test if any given point lies inside a cube by Comparing their coordinates to be greater or smaller than the given test point coordinates. But, I would like to know if there is a way to check for the same using Vectors. Any other approaches are also welcome

1

There are 1 best solutions below

0
On

A vector does not have an associated position with it, so you can't really test whether it is inside a cube or not.

If you mean it in the sense that a vector from the origin points to the point in question, just check to see if that point is inside the cube.

If you mean a line segment that has a position (which is what I'm assuming you meant), then simply test if both points are inside the cube. It is up to you how you want to handle edge cases, such as one point being on one of the cube's edges, or one point is slightly outside the cube.