2
votes

I need to compute the angle between the x-axis from A, and the point B, where the point A is the school and B is the student house. I have the longitude and latitude of the school and all students All the angles will be computed between the horizontal axis and the segment [School, Student] = [A, B].

I tried Math.atan in c# .. but it calculates the angle between the two points without taking into account the x-axis

will this method help me ?!

Cos(alpha) = (Lat B - Lat A) / distance(AB)

where alpha is the angle I need to find

thank you

1
Use Atan2 instead of atan.Kevin

1 Answers

6
votes

I'm going to assume that your longitudinal coordinates represent the distance of each point along the x-axis and that your latitudinal coordinates represent the distance of each point along the y-axis. If this is an incorrect assumption let me know.

y
|                   (B)
|                   /|
|                  / |
|                 /  |
|   distance(AB) /   |
|               /    | (LatB-LatA)
|              /     |
|             /      |
|            /       |
|           /alpha   |
|        (A)----------
|          (LonB-LonA)
|
|
|__________________________________ x
0

Then, in order to find your angle relative to the x-axis, you should apply one of the following rules:

sin(alpha) = (LatB - LatA) / distance(AB)
cos(alpha) = (LonB - LonA) / distance(AB)
tan(alpha) = (LatB - LatA) / (LonB - LonA)

By simply rearranging one of the equations by using the inverse of sin, cos, or tan, you should be able to find alpha in radians. For example...

alpha = Math.Asin((LatB - LatA) / distance(AB));
alpha = Math.Acos((LonB - LonA) / distance(AB));
alpha = Math.Atan((LatB - LatA) / (LonB - LonA));