I am working in the XY plane with two AABBs: the play space and a game object. My goal is to generate a random direction along their intersection going from the center of the game object in towards the play space. They should always intersect, but in the unexpected case that they don't, I will choose the direction from the game object's center to the play space's center.
I can think of 6 different intersection cases which I've illustrated in the attached image. The blue arcs represent the direction I want to randomly choose from and the green box is the play space.
So far my approach is to generate an AABB for the area where they intersect by taking the maximum of their minimum coordinates and the minimum of their maximum coordinates. I then test the four corners of the intersection AABB to see if they intersect the play space to get a list of intersection points. I can determine if the intersection points are on the edges of or inside the play space, but this is where I am stuck.
Can you please help me figure out to what to do next to get a random direction from one AABB in towards another?
[Edit:] I realized my first set of diagrams was incorrect to the results I wanted to model. These diagrams correctly show the wider available direction range when the game object intersects the play space but its center is not contained. This helped me see that there are actually only 3 cases: when the game object center is outside the play space, when the game object center is in the play space and their edges intersect, and when the game object is wholly within the play space.
I figured out an algorithm to solve my problem.
To return a random direction based on the arc endpoints: