## Box to Plane Intersection With Quaternions

KiroNeem
Unregistered

Post: #1
At the moment I'm trying to make an efficient box to plane intersection test for my game. My bounding boxes are oriented, and the rotation is represented by quaternions. I have only been able to find one equation to do box to plane intersections, which is.

|d| <= a1|n*A1| + a2|n*A2| + a3|n*A3|

d = distance from the center of the box to the plane.
a1-a3 The extents of the box from the center.
n = Normal of the plane
A1-A3 = The x,y,z axis of the box

http://www.gamasutra.com/features/19991018/Gomez_7.htm

I have tested this equation and it works perfectly. Although my problem is when I begin to encorperate the quaternions into the equation for the box rotation. I have been successful by rotating each axis by the quaternion, although I'm doing way to much math for this to be efficient. My only other idea was rotate the normal by the quaternion, although that failed horribly.

Does anyone have any thoughts on how I might accomplish this better?
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
KiroNeem Wrote:My only other idea was rotate the normal by the quaternion, although that failed horribly.

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Member
Posts: 142
Joined: 2002.11
Post: #3
KiroNeem Wrote:At the moment I'm trying to make an efficient box to plane intersection test for my game. My bounding boxes are oriented, and the rotation is represented by quaternions. I have only been able to find one equation to do box to plane intersections, which is.

|d| <= a1|n*A1| + a2|n*A2| + a3|n*A3|

d = distance from the center of the box to the plane.
a1-a3 The extents of the box from the center.
n = Normal of the plane
A1-A3 = The x,y,z axis of the box

http://www.gamasutra.com/features/19991018/Gomez_7.htm

I have tested this equation and it works perfectly. Although my problem is when I begin to encorperate the quaternions into the equation for the box rotation. I have been successful by rotating each axis by the quaternion, although I'm doing way to much math for this to be efficient. My only other idea was rotate the normal by the quaternion, although that failed horribly.

Does anyone have any thoughts on how I might accomplish this better?

Apply the transformation to the vertices of the box to get them in the same coordinate system as the plane. For the box to insersect the plane, it is necessary and sufficient that at least one vertex of the box lies above the plane, and at least one vertex lies below the plane.

To figure out which vertices are above or below the plane, apply the quaternion to each vertex so that it is in the same coordinate system as the plane. Now take each vertex of the box, and find the difference between its location and some location on the plane. Make this a vector and dot it with the normal vector of the plane. If the result is negative then you are below the plane, if it is positive you are above the plane. This is because the result of the dot product is a multiple of the cosine of the angle. So if two of your dot products differ in sign, then the box collides with the plane.
KiroNeem
Unregistered

Post: #4
Holmes Wrote:Apply the transformation to the vertices of the box to get them in the same coordinate system as the plane.

I thought about that when first trying to figure this out. The suggest method would work, although to rotate each vertex by the quaternion would be even slower then just rotating each axis vector and using the posted equation.
Sage
Posts: 1,403
Joined: 2005.07
Post: #5

...............

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Member
Posts: 142
Joined: 2002.11
Post: #6