-2

I've been looking around for an algorithm that could tell me if a point is inside a box, but I still haven't found what I'm looking for.

Basically I have a 2D rectangle [Upper_X, Lower_X, Upper_Y and Lower_Y] which is translated and rotated in a 3D world (I've got both world and orientation matrixes), I want to build up a box from this rectangle (in order to considerate some kind of epsilon margin while checking) and check if a point P is inside it.

How can I accomplish this? I'm really sorry, please be patient I'm not very good in algebra and geometry stuff so just write a c++ example code it would be easier for me to understand it.

bolov
  • 72,283
  • 15
  • 145
  • 224
user3813522
  • 37
  • 1
  • 6
  • If you are good at algebra, than just go through all 6 planes of the box and check if the [point in front of the plane](http://stackoverflow.com/questions/15688232/check-which-side-of-a-plane-points-are-on) (or back of the plane.. depending on how you get the plane information). – wendelbsilva Feb 24 '16 at 16:18
  • BTW, If you have the transformation matrix, transform the box back to the origin (so the box is aligned with the axis).. transform the point the same way and than check if the point is inside the box with a [simple if](http://www.miguelcasillas.com/?p=24). – wendelbsilva Feb 24 '16 at 16:26
  • If the box is defined by OX, OY, OZ and your point is P, you can check 0 <= OX dot OP <= |OX|, 0 <= OY dot OP <= |OY|, 0 <= OZ dot OP <= |OZ|, or equivalently [OX OY OZ]^T OP in [0, |OX|] x [0, |OY|] x [0, |OZ|]]. As mentioned above if you already have a matrix you can use that. The dot products are just projecting onto each axis. – llllvvuu Feb 24 '16 at 16:44
  • I'm voting to close this question as off-topic because it's about geometry. – BartoszKP Feb 24 '16 at 16:47

1 Answers1

0

Best way to approach this is to grab a paper and pencil and draw your rectangle with your lower_X,upper_X and your lower_Y, upper_Y. Then chose a random point in the box. Check to see what conditions make this case true. For example if your point is in the box then your point is located somewhere between your lower_X and upper_x, if that is true then check if point is also between your lower_Y and upper_y. If both cases are true then you know your point is located in the box. Hope I made it little more clear for you.