Search code examples
imageviewcompassnavigatordegrees

Calculate the interior angle of a triangle


i'm trying to create a simple navigator, with an arrow that indicate the direction from the location where i'm to the location saved in the map, like a compass with north. i've two location (long and lat), start point and final point. The arrow must rotate from north to the final point direction. I need to calculate this movement i degrees. It's like two side of a triangle, and the movement is the interior angle.

How can calculate this angle, knowing the two distance?


Solution

  • This is just basic trig:

    deltaY = P2_y - P1_y
    deltaX = P2_x - P1_x
    angleInDegrees = atan2(deltaY, deltaX) * (180 / PI)
    

    Via this answer.