Calculate direction angle from two vectors?

后端 未结 4 905
时光说笑
时光说笑 2021-02-03 10:13

Say I have two 2D vectors, one for an objects current position and one for that objects previous position. How can I work out the angular direction of travel?

This image

4条回答
  •  温柔的废话
    2021-02-03 10:55

    If you're in C (or other language that uses the same function set) then you're probably looking for the atan2() function. From your diagram:

    double theta = atan2(x1-x, y1-y);
    

    That angle will be from the vertical axis, as you marked, and will be measured in radians (God's own angle unit).

提交回复
热议问题