-2

There are three location on map. Location A , Location B and Location C.

There are three location on map. Location A , Location B and Location C.

I have only latitude and longitude of all three location.

Now i want to find angle "B" with respect to "A" and "C" in android map.

Please help me.

Darsh Patel
  • 1,015
  • 9
  • 15

1 Answers1

1

see for example this link.

In pseudo-code the procedure is more or less like this:

Assuming A, B and C are 2D-vectors with an x and y component.

//compute vectors ba and bc
ba = A-B
bc = C-B
//normalize the vectors (divide by the length)
ban = ba / sqrt(ba.x*ba.x + ba.y*ba.y)
bcn = bc / sqrt(bc.x*bc.x + bc.y*bc.y)
//compute the cosinus of the angle using the dot-product
cosAngle = ban.x * bcn.x + ban.y * bcn.y
//compute the angle
angle = acos(cosAngle)

Note: when you subtract two vectors, subtract the individual coordinates:

ba.x = A.x - B.x
ba.y = A.y - B.y

Division of a vector by a scalar is similar:

ban.x = ba.x / length
ban.y = ba.y / length
azt
  • 2,100
  • 16
  • 25
  • How can i find vector on android map(ba and bc)? – Darsh Patel Apr 20 '15 at 07:49
  • I don't know android map. But I guess there is some way you can get the two coordinates of the point. Once you have the coordinates you can compute it as outlined above. Either use an existing vector library, write your own, or simply maintain the x and y coordinates in separate variables. – azt Apr 20 '15 at 07:54
  • That's problem. I have only latitude and longitude of all three location. Nothing else. – Darsh Patel Apr 20 '15 at 07:57
  • Another stepping stone might be to get the coordinates in an Euclidean space. Maybe you only get the coordinates as longitude and latitude. It gets more difficult for large distances which span a larger portion of the globe, since then you have to compute the angle between the arcs on a sphere. Then we would need to compute it in 3D. – azt Apr 20 '15 at 07:58
  • Your way is correct but my problem is that How can i apply it on map where i have limited information(only lat and lng of location) – Darsh Patel Apr 20 '15 at 08:03
  • OK, so it is more difficult than on first sight. There are approximations as for example in this post: http://stackoverflow.com/questions/16266809/convert-from-latitude-longitude-to-x-y. But the basic question is then, what angle you are looking for. The earth is approx. a sphere. There are a lot of different mappings to 2D maps (e.g. http://en.wikipedia.org/wiki/World_Geodetic_System#A_new_World_Geodetic_System:_WGS_84). So do you want to compute the andle on a specific map? Or do you want to have the 3D-angle between the 3 3D points in space? Or maybe with respect to the center of earth? – azt Apr 20 '15 at 08:09