# Get intersected volume of two planes in 3D

I'm working on AABB - AABB collision response and I'm having trouble figuring one part out. My situation is as follows (see image).

I have a player AABB (blue) and an object which collides (brown). I've drawn a few faces for both AABB's. The player moves towards the cube and collides with two planes (colliding planes have their normal's drawn). These normals will be returned in the code in the 'normals' vector. I then check the opposing planes and try to get the volume of the intersected plane (right side of image).

I based my face detection algorithm on the following question : AABB - AABB Collision, which face do I hit?

The Two AABB's colliding (blue is Player AABB and brown is object)

If I have multiple normals returned (which happens when two faces collide) I want to calculate the highest intersected volume between the collided faces and take that normal as the normal to base my collision response on (right side of image). It works for some faces but for the other half it doesn't work and I assume this has to do with change of vertex order which make my substractions pointless in some cases.

Is there some general way to calculate the volume of two intersecting planes in 3D that helps me resolve my response?

Code attempt for calculating highest volume between two (not working as it should):

functionThatDoesCollisionResponse
{
[...]
// Calculate size differences first
for(int i = 0; i < normals.size(); i++) // Normals is vector filled with all intersected plane normals.
{
Vector oppNormal = normals[i].Negative();
Plane pFace = this->GetPlaneFromNormal(player, oppNormal); // Returns plane with specified normal
Plane oFace = this->GetPlaneFromNormal(object, normals[i]);
sizeDifs.push_back(this->CalculateSizeDifference(pFace, oFace)); // Pushes differences of size in Vector for later calculation
}

// Don't take average but take highest intersected volume plane
GLfloat min = 9999999.99f;
Vector bestNormal;
for(int i = 0; i < sizeDifs.size(); i++)
{
GLfloat opp = sizeDifs[i].x * sizeDifs[i].y * sizeDifs[i].z;
if(opp < min)
{
min = opp;
bestNormal = normals[i];
}
}
[...]
}

Vector CollisionEngine::CalculateSizeDifference(Plane p1, Plane p2)
{
GLfloat xDif = p1.topLeft.x - p2.topLeft.x;
GLfloat yDif = p1.topLeft.y - p2.bottomLeft.y;
GLfloat zDif = p1.topLeft.z - p2.bottomRight.z;
return Vector(abs(xDif), abs(yDif), abs(zDif));
}


1. The intersection between two planes is a line...
2. Work with bounding boxes not with planes...

don't generate a plane from a normal, generate the bounding box and its corners... this way you will know what are the front, back, right, left, top and bottom sides, and the code is easier...

if there are true AABB, you only need two points that keep min and max coordinates... and then knowing the intersection is much easier...

• Thanks for the answer! 1. I am looking for the volume that two paralell planes overlap so I can't do much with a line. 2. I'm using planes to eventually work my way up to OBB's and switched to planes since it made it eassier to generate the collision normal if a collision occurs, or am I wrong?
– Joey
Mar 4 '13 at 6:24
• 1. Planes are infinite :) 2. OBB collision are harder to implement that AABB collisions and maybe require other approches... due to intersection volumes are not boxes and that you will have to work in object space not in world space 3) Maybe sat in 2D inspire you to get a collision response for AABB. metanetsoftware.com/technique/tutorialA.html
– Blau
Mar 4 '13 at 9:31
• 1. In the plane equation yes, I do have variables that represent four corners of the plane though. 2. Could be yeah, I'll have to do some more research into OBB's. What do you mean with working on object space. Is there some way to translate my 3D planes into 2D space? (would solve the issues probably)? 3. Read a bit about the axis theorom but not much, would SAT solve my issues?
– Joey
Mar 4 '13 at 9:55
• think that in object space like if you were inside the cube, and (0,0,0) is one corner of the cube... you can translate the other cube to that space, and then making calculations is easier... because now there is only one cube rotated... :)
– Blau
Mar 4 '13 at 21:18
• Yeah that makes sense, the issue was that the topleft of every plane differs on each face, making it difficult to get the intersecting volume. I'll be doing some extra research into figuring out how to translate to object space :)
– Joey
Mar 5 '13 at 6:35