Find angle between two points, respective to horizontal axis?

前端 未结 2 1291
死守一世寂寞
死守一世寂寞 2021-01-24 06:38

I have two points, one is always at the origin (0,0), and the other can be anywhere else in the world. I\'d like to find the angle between them, respective to the horizontal axi

相关标签:
2条回答
  • 2021-01-24 07:00

    Most programming languages/APIs provide a function, atan2(), which finds the angle and takes the quadrant into consideration. Just use that.

    0 讨论(0)
  • 2021-01-24 07:18

    First we would like to find the equation of the straight line that connects the two points:

    Let p = (x0,y0) be the second point. if x=0 than the answer is 90 deg. otherwise let m be y0/x0.

    y = m(x-x0) +y0

    tg^-1 (that is arctg) of m is the angle.

    also note that if (x0,y0) == (0,0) than the angle is undefined

    0 讨论(0)
提交回复
热议问题