I have implementen the separating axis theorem in java. The collision detection itself works great. But i am stuck when it comes to resolve the collision.
my method to get the translation looks like this:
public float getOverlap(final Projection other) {
float start = m_min > other.m_min ? m_min : other.m_min;
float end = m_max < other.m_max ? m_max : other.m_max;
float translation = end - start;
return translation;
}
Lets say the projection of the two rectangles in the picture looks like this.
R1.min = 2
R1.max = 8
R2.min = 5
R2.max = 11
When i check R1 vs. R2 the translation will be 3 When i checl R2 vs. R1 the translation also will be 3
now i add the translation to the normalized axis
Normalized axis = Vector(1,0)
Translation Vector = Vector(1,0)*3 = Vector (3,0)
And now R1 and R2 both move 3 points to the right, but they are suposed to move in different directions. R1 should move Vector(-3,0), R2 should move Vector(3,0).
how can i compute the right direction?