# can someone explain me this Collition detection Test function

Hello everyone

I saw the function bellow in the book, real time collision detection, and I have to say I don’t understand a single thing (math is not my strong subjet) and I would like to understand it.
If someone could be kind enought to explain it to me in a simple way I would apreciate it.

``````
// Region R = { x | x = c+r*u+s*u+t*u }, |r|<=e, |s|<=e, |t|<=e
struct OBB {
Point c; // OBB center point
Vector u; // Local x-, y-, and z-axes
Vector e; // Positive halfwidth extents of OBB along each axis
};

int TestOBBOBB(OBB &a, OBB &b)
{
float ra, rb;
Matrix33 R, AbsR;

``````

//if u is the regular column the estracted rotation matrix why this dot product?

``````
// Compute rotation matrix expressing b in a’s coordinate frame
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
R[i][j] = Dot(a.u[i], b.u[j]);

``````

Why this dot product to.
I thought to convert a point P which is in the local space of B to local space of A, I would have to multiply P by the in worldspace of B then, multiply it by the inverse of the localmatrix of A.

``````
// Compute translation vector t
Vector t = b.c - a.c;
// Bring translation into a’s coordinate frame
t = Vector(Dot(t, a.u), Dot(t, a.u), Dot(t, a.u));

``````

Don’t know what happend here either.

``````
// Compute common subexpressions. Add in an epsilon term to
// counteract arithmetic errors when two edges are parallel and
// their cross product is (near) null (see text for details)
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
AbsR[i][j] = Abs(R[i][j]) + EPSILON;

// Test axes L = A0, L = A1, L = A2
for (int i = 0; i < 3; i++) {
ra = a.e[i];
rb = b.e * AbsR[i] + b.e * AbsR[i] + b.e * AbsR[i];
if (Abs(t[i]) > ra + rb) return 0;
}
// Test axes L = B0, L = B1, L = B2
for (int i = 0; i < 3; i++) {
ra = a.e * AbsR[i] + a.e * AbsR[i] + a.e * AbsR[i];
rb = b.e[i];
if (Abs(t * R[i] + t * R[i] + t * R[i]) > ra + rb) return 0;
}

``````

Here I know he is extracting all the points of A and B, but I thought they need to be projected on every axis using the the dot product, is that the reason he used the dot avobe?.

``````
// Test axis L = A0 x B0
ra = a.e * AbsR + a.e * AbsR;
rb = b.e * AbsR + b.e * AbsR;
if (Abs(t * R - t * R) > ra + rb) return 0;
// Test axis L = A0 x B1
ra = a.e * AbsR + a.e * AbsR;
rb = b.e * AbsR + b.e * AbsR;
if (Abs(t * R - t * R) > ra + rb) return 0;
// Test axis L = A0 x B2
ra = a.e * AbsR + a.e * AbsR;
rb = b.e * AbsR + b.e * AbsR;
if (Abs(t * R - t * R) > ra + rb) return 0;
// Test axis L = A1 x B0
ra = a.e * AbsR + a.e * AbsR;
rb = b.e * AbsR + b.e * AbsR;

if (Abs(t * R - t * R) > ra + rb) return 0;
// Test axis L = A1 x B1
ra = a.e * AbsR + a.e * AbsR;
rb = b.e * AbsR + b.e * AbsR;
if (Abs(t * R - t * R) > ra + rb) return 0;
// Test axis L = A1 x B2
ra = a.e * AbsR + a.e * AbsR;
rb = b.e * AbsR + b.e * AbsR;
if (Abs(t * R - t * R) > ra + rb) return 0;
// Test axis L = A2 x B0
ra = a.e * AbsR + a.e * AbsR;
rb = b.e * AbsR + b.e * AbsR;
if (Abs(t * R - t * R) > ra + rb) return 0;
// Test axis L = A2 x B1
ra = a.e * AbsR + a.e * AbsR;
rb = b.e * AbsR + b.e * AbsR;
if (Abs(t * R - t * R) > ra + rb) return 0;
// Test axis L = A2 x B2
ra = a.e * AbsR + a.e * AbsR;
rb = b.e * AbsR + b.e * AbsR;
if (Abs(t * R - t * R) > ra + rb) return 0;
// Since no separating axis is found, the OBBs must be intersecting
return 1;
}

``````