# Calculating Angle between two 2D Points, WITH A CATCH!

• Oct 1st 2009, 11:03 PM
pdub
Calculating Angle between two 2D Points, WITH A CATCH!
I need some help calculating the angle between two 2d points, but theres a slight twist. I'm working with a weird way of representing rotation.

Going clockwise, starting at WEST we have 0 degrees. At NORTH, it's -90 degrees. At EAST, it swaps from -180 degrees to 180 degrees, at SOUTH its 90 degrees, back down to 0 at WEST. Here is a picture:

http://img32.imageshack.us/img32/1954/rotdiagram.th.png

What I need to do, is write a function that takes two 2D points, and calculates the angle from point A to point B, as this wierd 0 to -180, 180 to 0, value.

Anyone have any ideas? And no, I cannot use a standard 0-360 degrees representation, I have to solve this problem using this method of representing the angle.

Many thanks!
• Oct 4th 2009, 07:45 AM
pflo
This would be an angle measured in standard position.

Assume the first point is at the origin. Then the difference in x values would be the x-coordinate of the second point and the difference in y-values would be its y-coordinate. Draw a quick sketch to see this. Then in the sketch you should be able to see a right triangle using the x-axis and a vertical to the second point.

Use this triangle to calculate the angle using right-triangle trig.

$a = tan^{-1}(\frac{y_2-y_1}{x_2-x_1})$

This gives the angle in standard position.

Note that you have taken the opposite of this twice, thus cancelling each other out. First, West is 0 degrees instead of East (as it would be in standard position). And second, North is at -90 degrees instead of South (as it would be in standard position).