Calculation Of Directional Rotation Angles From 3 Points
What I'm trying to do is find the angle of rotation between lines formed by three consecutive points. These are sequential points, so the direction of rotation matter. My input is
Solution 1:
You have the points A, B and C. I'm assuming from your description that B is the rotation point. That is, the vector BA transforms into BC.
- Create the vectors BA (A-B) and BC (C-B).
- Calculate the angle of the vectors (make them positive) and their difference
- The difference in angles between the vectors is the rotation angle.
Using numpy makes this easy. Like this:
In [1]: import numpy as np
In [2]: A = np.array([283907, 971700])
In [3]: B = np.array([284185, 971634])
In [4]: C = np.array([284287, 971507])
In [5]: BA = A - B
In [6]: BC = C - B
In [7]: BA
Out[7]: array([-278, 66])
In [8]: BC
Out[8]: array([ 102, -127])
In [9]: s = np.arctan2(*BA)
In [10]: if s < 0:
....: s += 2*np.pi
....:
In [11]: s
Out[11]: 4.9454836529138948
In [12]: e = np.arctan2(*BC)
In [13]: if e < 0:
e += 2*np.pi
....:
In [14]: e
Out[14]: 2.4649341681747883
In [15]: delta = e - s
In [16]: np.degrees(delta)
Out[16]: -142.12501634890182
In [17]: delta
Out[17]: -2.4805494847391065
A positive angle is counter-clockwise.
Post a Comment for "Calculation Of Directional Rotation Angles From 3 Points"