You can also use arccosine if your string is in the form [r_x,r_y] , where r_x is the change in x and r_y is the change in y.
angle = arccos( r_x/( r_x*r_x + r_y*r_y ) )
This is a bit more opaque, but it is basically the law of the product in terms of:
angle = arccos (r . v)
Where r and v are unit vectors (vectors of length 1). In our case, v is the vector [1,0] , and r is
[r_x,r_y] / (r_x^2+r_y^2)
to make it a unit vector.
Justin L.
source share