PDA

View Full Version : Box to Plane Intersection With Quaternions


KiroNeem
2006.06.24, 08:41 PM
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?

unknown
2006.06.24, 09:19 PM
My only other idea was rotate the normal by the quaternion, although that failed horribly.

un-rotate instead.

Holmes
2006.06.25, 02:47 AM
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
2006.06.25, 08:52 PM
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. :(

unknown
2006.06.25, 08:55 PM
un-rotate instead.

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

Holmes
2006.06.25, 09:34 PM
unrotate instead

Seconded then.

KiroNeem
2006.06.25, 09:44 PM
Sorry about replying in the last post. Actually that works perfectly, thank you.