# Angle points calculation

i am developing an application for iPhone, and i need some help to solve this difficult problem.

I am working with the device compass, from where i get the angle where the iPhone is oriented.

I need to check what points are on a angle view(oriented with the compass) from the current location.

I have no idea how to make it, i have been thinking all the afternoon. Any consideration is apreciated. Thanks!!!!

-
The picture is not really helpful. Could you comment on it? – Raskolnikov Feb 14 '11 at 21:58
the points are coordinates on a map. The current Position is where the user is... What part is confused to you?? Thanks!! – saimonx Feb 14 '11 at 22:11

## 2 Answers

So from the compass you have bearings that are the limits of visibility. In your figure they appear to be $k+20^{\circ}$ and $k-20^{\circ}$ Then take the difference in position between the phone and each point. You can feed this to the Atan2 function to get the bearing (remember to convert between degrees and radians). If it is in range, you are good.

-
you mean, to take the distance between the phone and each point? Thanks – saimonx Feb 14 '11 at 22:05
Yes, take the distance north/south (x)and the distance east/west (y). Then the bearing to the point is Atan2(y,x) (if zero is north) Subtract this from the angle the phone is pointing and if it is within 20 degrees of zero you can see it. – Ross Millikan Feb 14 '11 at 22:49
Ross, please check my new answer! – saimonx Feb 15 '11 at 15:43

I can't get it, i have do the following.

Point 1(current position): 36.837147 -2.469118

Point 2: 36.837437 -2.469040

Point 3: 36.837452 -2.469162

Point 4: 36.837547 -2.469532

The angle given by the iPhone is 155º.

What i do is:

float x1=point1.longitude;

float y1=point1.latitude;
float x2=point2.longitude;
float y2=point2.latitude;

float x = x2 - x1;
float y = y2 - y1;

float angle = atan2(y, x);


Then the result is:

Angle between:

P1, P2=1.307330

P1, P3=1.713568

P1, P4=2.372586

But... Now you say to substract from the phone angle the obtained angle.For the three cases, it is something like 154.xx.

What i'm doing wrong? The true situation says that the P2 and P3 are inside 20º, but not the P3.

Thank You!!!

-
You should edit your original post instead of posting this as an answer, please. – Raskolnikov Feb 15 '11 at 16:11
we're sorry, but as a spam prevention mechanism, new users aren't allowed to post images. Earn more than 10 reputation to post images. – saimonx Feb 15 '11 at 16:24
Atan2 is giving results in radians, not degrees, so you need to multiply by $180/\pi$. This gives the bearing from P1 to P2 as about 75 deg, which seems about right given that it is mostly north and a bit east. You also have a potential loss of precision problem when you subtract the coordinates as they are within .001 of each other it is only the numbers below that which contribute. – Ross Millikan Feb 15 '11 at 16:55
155-75=80, 80 it's outside the angle view, right? But this is not possible, the P2 is inside the angle view. What calculation am i doing wrong? Thanks!! – saimonx Feb 15 '11 at 21:59