I stumbled across this implementation for a projection intersection test to use in a SAT test:
// aCorn and bCorn are arrays containing all corners (vertices) of the two OBBs
private static bool IntersectsWhenProjected( Vector3[] aCorn, Vector3[] bCorn, Vector3 axis ) {
// Handles the cross product = {0,0,0} case
if( axis == Vector3.zero )
return true;
float aMin = float.MaxValue;
float aMax = float.MinValue;
float bMin = float.MaxValue;
float bMax = float.MinValue;
// Define two intervals, a and b. Calculate their min and max values
for( int i = 0; i < 8; i++ ) {
float aDist = Vector3.Dot( aCorn[i], axis );
aMin = ( aDist < aMin ) ? aDist : aMin;
aMax = ( aDist > aMax ) ? aDist : aMax;
float bDist = Vector3.Dot( bCorn[i], axis );
bMin = ( bDist < bMin ) ? bDist : bMin;
bMax = ( bDist > bMax ) ? bDist : bMax;
}
// One-dimensional intersection test between a and b
float longSpan = Mathf.Max( aMax, bMax ) - Mathf.Min( aMin, bMin );
float sumSpan = aMax - aMin + bMax - bMin;
return longSpan < sumSpan; // Change this to <= if you want the case were they are touching but not overlapping, to count as an intersection
}
I now don't really get why there is a check for the zero vector, i.e. these lines right here:
if( axis == Vector3.zero )
return true;
Why can we immediately say that the projections intersect, when there is a zero vector as projection axis?
The code is from Acegikmo answer on this question right here: How many and which axes to use for 3D OBB collision with SAT
He just states, that:
The cross product will give you a zero vector {0,0,0} when any two axes between the objects point in the same direction.
Can anyone clarify this?