# Getting the angle between two objects?

I have a set of boxes which create a sort of path, they don't intersect very smoothy and to help that process I'm trying ot find a way to get an angle between them that can make it easier to generate another box between the intersection points.

Here's a pic of what I mean, the crudely drawn yellow arrows are basiclaly the angles I'm trying to find to put boxes there: • How are you storing the boxes? Are they point, rotation, width, height or 4 points? – Tetrad Sep 10 '11 at 6:33

That vector can be obtained simply by summing up the normals of the boxes faces and normalize. The normal vector even point outside the box so the sum vector points toward the direction where the boxes exit from the intersection. along with the vector you need the intersection segment too (if you still don't have it)

you can use atan2. for example:

float radians = Math.atan2(object2.y - object1.y, object2.x - object1.x);


and then if you want the degrees its like this:

float degrees = radians * 180 / PI


Since I can't comment yet, I'll just put it as an answer:

As stas said, use Atan2, but be careful. Atan2 returns 0 to PI like a normal angle, BUT it returns 0 to -PI for the lower half of the 'circle'.

And remember that in the computer, angles start at 3 o'clock for 0, 12 noon for (PI/2), 9 for PI, and 6 for (3PI/2) or -PI in this case. You'll need to convert anything that you receive as a negative.