Finding points inside of a box

96 Views Asked by At

I have a set of points in 3D that define a large, complex object. These points are rendered in OpenGL for an Android app that I am programming.

In this app, the user translates the center of the box to a point on this object. When the box is locked onto a point, the box can be stretched/squeezed (in either the X,Y, or Z direction) and rotated along the X,Y, and Z axis, with the point of rotation being the point on the object.

The user then presses a button, and all the points from the object that lie inside of the box are supposed to be found and saved. This is where I have am having difficulty.

Without rotation, my problem is easy. I just iterated through all my points and checked whether the point on my current iteration fell within this range (pseudocode is below):

if (pointX <= pointOnObjectX + width/2 and pointX >= pointOnObjectX - width/2 and pointY <= pointOnObjectY + length/2 and pointY >= pointOnObjectY - length/2 and pointZ <= pointOnObjectZ + height/2 and pointZ >= pointOnObjectZ - height/2)

Save Point

Now obviously, when the user rotates the box, this does not work. Given my limited knowledge of Linear Algebra, does anyone have any idea on how I can make my calculation to see which points are inside my rotated box? Here is some data that I have:

  1. All the points of my object
  2. The center of the box
  3. The length/width/height of the box
  4. Rotation matrix for my box