How to find the smallest angle between two rectangles?

48 Views Asked by At

I want to find the minimum angle between two rectangles.

If they are exactly paralell, the result should be 0. If they are orthogonal to oneanother it should be 0 too. I want values only between 0 and 45 degrees.

I came up with this formula, where I end up having results between 0 and 2025. the two alphas are the angles of the longer edge of the rectangle.

example

Here is an example of the two extreme cases with the desired formula output of 0 and 45 degrees. The two alphas that I have are the main orientation of each rectangle. They can each range from 0-360°.

enter image description here