Find angle between two points, respective to horizontal axis?

前端 未结 2 1295
死守一世寂寞
死守一世寂寞 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: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

提交回复
热议问题