public static void ExpandMinkowskiSum(float marginA, float marginB, Vector3 direction, ref Vector3 toExpandA, ref Vector3 toExpandB)
{
float lengthSquared = direction.LengthSquared();
if (lengthSquared > Toolbox.Epsilon)
{
lengthSquared = 1 / (float)Math.Sqrt(lengthSquared);
//The contribution to the minkowski sum by the margin is:
//direction * marginA - (-direction) * marginB.
Vector3 contribution;
Vector3.Multiply(ref direction, marginA * lengthSquared, out contribution);
Vector3.Add(ref toExpandA, ref contribution, out toExpandA);
Vector3.Multiply(ref direction, marginB * lengthSquared, out contribution);
Vector3.Subtract(ref toExpandB, ref contribution, out toExpandB);
}
//If the direction is too small, then the expansion values are left unchanged.
}
}