# How to get a translation vector in a certain direction? SAT

I'm using the seperating axis thereom for discrete collision detection. I have code to find the minnimum translation vector (or distance) to seperate two shapes but how can I adjust it to get a vector in a certain direction that seperates the shapes? For example: If a box A is overaping box B 10 pixels horizontaly and 40 pixels vertically the MTV would calculate to move the box horizontally 10 px or so but I want to seperate the boxes vertically (move 40px up). How can I adjust my code to calculate a MTV in a direction of my choosing?

    const Vector2 ShapeImpl::CalcDisplacement(const AxesVec &axes, const Shape &a, const Shape &b) const
{
Vector2 displacement;
Precision_t Overlap = std::numeric_limits<Precision_t>::infinity();
Axis smallest;

for (auto && axis : axes)
{
const Projection pA = b.Project(axis);
const Projection pB = a.Project(axis);

// No Collision
if (!pA.IsOverlap(pB))
return Vector2(0, 0);

else
{
const Precision_t o = pA.GetOverlap(pB);

if (std::abs(o) < std::abs(Overlap))
{
Overlap = o;
smallest = axis;
}
}

}

displacement = smallest * Overlap;

return displacement;
}

• Do you only have boxes? – Bálint Aug 17 '17 at 7:42
• no. I have convex shapes – Greg Williamson Aug 17 '17 at 7:49