I am trying to implement the following. I have two bounds A and B, I want to transform box B so that the intersection between A and B no longer exists. I’m not sure how to calculate the shift, i want to maintain the direction, i.e the red line.

Haven’t written much code, pretty stuck with the math.
var a = new Rectangle(40, 40, 20, 20);
var b = new Rectangle(25, 30, 20, 20);
So for the case you’ve provided, the shift in b.x (dx) can be calculated as
a.x - b.length - b.x. The shift in b.y (dy) can then be calculated in terms of keeping slope constant. So solve for dy indx/dy = (a.x - b.x)/(a.y - b.y), and that gets you the change in y as well.However, this is specific to the case you described. Among other things, you need to think about what happens if A and B are flipped, what happens if A.x = B.x, what happens if A.y = B.y, and what happens if the difference in x is smaller than the difference in y. Drawing pictures will probably help immensely, on chart paper if you have it, on blank computer paper if you don’t. Hope this is a good start.