# How to find the angle of a rectangle vertex

before I go further I want you to know that I'm developing a collision detection system in a programming language (Javascript).

I'm not used to math terms (it was like 10 years ago when I was in school), but I think this should be simple:

I need the formula to find this angle.

In the picture you can see I need the angle of the first vertex, but I also need the formula to find the other angles to the bottom right vertex, the bottom left vertex and so on.

Although the rectangle size is variable, I have access to its width and height, and also the X,Y coordinate of its center point.

Thank you beforehand!

• @JuanBonnet: Is that point at the exact center?
– Moo
Commented Jan 1, 2016 at 20:55
• Not in my drawing, but IT IS in the software hehe Commented Jan 1, 2016 at 20:56
• Let's say I'm developing a videogame, and that rectangle is just a box that can be anywhere in a X,Y space, the center is variable relative to the whole 2D space, but not variable inside the rectangle itself. Commented Jan 1, 2016 at 20:58

To find the "bearings" (angles) to the rectangle's vertices, all that is needed are the height (the vertical, Y direction: let's call it $h$) and the width (the horizontal, X direction: let's call it $w$). The coordinates of the center are not needed.

The upper-right vertex has bearing $\tan^{-1}\frac wh$ where $\tan^{-1}$ is the arctangent function, sometimes called $\operatorname{atan}$ or $\arctan$. I believe in javascript you would write

$$\operatorname{Math.atan}(w/h)$$

The lower-right vertex has bearing

$$\operatorname{Math.PI}-\operatorname{Math.atan}(w/h)$$

The lower-left vertex has bearing

$$\operatorname{Math.PI}+\operatorname{Math.atan}(w/h)$$

and the upper-left vertex has bearing

$$2*\operatorname{Math.PI}-\operatorname{Math.atan}(w/h)$$

Do you need further explanation of these formulas?

• It works perfect, plus you used the native Javacript functions, thank you very much sir, I hope we can meet again when I have more questions now that I'm diving into complex computing stuff! Much respect and happy new year! Commented Jan 1, 2016 at 21:22