1
votes

I was working on a collision detection algorithms for an OBB algorithm and I've reached the point where it works but I am finding the lines equivalent in box space in a really ineffective way by means of some hacked away code (using Ogre3d nodes) but I would really like it to be done as easily as possible with some small algorithms.

Basically I have 2 points and a box (for simplicity purposes a 1 point solution can be used for each) and these two points make up a line. The box can be rotated any way it wants so I need to rotate the box so it is axis aligned. To do this I also need the points to rotate to the same axis aligned space. I was able to do this when I worked in 2 dimensions but I am having trouble finding a solution with 3d.

I understand the concept easily illustrated by thinking about sticking a pencil into a clay box then rotating the box to be axis aligned and then doing calculations of it being axis aligned making it much easier but the code behind getting the lines to rotate are giving me trouble. Any help would be appreciated :)

1

1 Answers

0
votes

If you have the box in 3D, then you can think of it as generated by three unit vectors a, b, and c, each of which exists in 3-space, along with some origin point O. As a preprocessing step, let's begin by assuming that O is the origin and therefore that the points you have in the box are defined by two vectors u = (x0, y0, z0) and v = (x1, y1, z1). The question you're now interested in answering is - assuming that we applied a rotation transformation to rotate the box so that a, b, and c were axis-aligned to the x, y, and z axes, respectively, what would the points u and v be?

I could be wrong about this, but I think that this can be done with some simple math. You can begin by thinking about the transformation you would do to get from the normal canonical basis into the basis defined by the vectors of your box. This matrix is given by

      | | | 
M = ( a b c )
      | | | 

That is, the matrix whose columns are a, b, and c.

Now that we have the matrix M, we can think about the matrix that would invert this transformation (i.e. mapping the unit vectors a, b, and c to the axis-aligned unit vectors) as the inverse of M, M-1. However, if you've chosen the vectors a, b, and c defining your bounding box to be orthonormal (which, assuming that the vectors are orthogonal, you can do by normalizing them), then M-1 = MT, the transpose of M, which is given by

        - a -
M^T = ( - b - )
        - c -

That is, the matrix whose first row is a, whose second row is b, and those third row is c. Given these vectors, you can figure out where points u and v would be if you rotated the box as MTu and MTv, both of which are expressions that shouldn't be too hard to compute.

Hope this helps!