I have a set of points in 3D space and I have defined a vector form one point to another. I want to find angle of each of this vector with reference to the vector defined as a reference.
The vector defined as a reference is between this two points,
head = [0.5806 0.50239 0.54057]
tail = [0.5806 0.50239 0. ]
Reference vector is defined as,
v_reference = head - tail
The set of points from which I have defined a vector from one point to another is as follows,
x y z
0 0.722950 0.611143 0.154976
1 0.722887 0.611518 0.152955
2 0.722880 0.612001 0.150593
3 0.722910 0.612509 0.148238
4 0.723049 0.613053 0.146069
5 0.723113 0.613583 0.143714
6 0.722763 0.613838 0.141321
7 0.721956 0.613876 0.138467
8 0.721638 0.614167 0.136008
9 0.720665 0.614093 0.133143
10 0.719612 0.613956 0.130317
11 0.718672 0.613882 0.127562
12 0.717771 0.613870 0.124638
13 0.716533 0.613668 0.121512
I have defined vector from one point to another, the points used for defining those vectors is shown in the table above.
For defining the vectors I have used following approach,
vector[i] = data[i+1] - data[i]
I want to find angle of each of this vector with respect to the reference vector (v_reference).
I have used following approach for angle computation,
def dotproduct(v1, v2):
"""This function computes dot product of two vectors."""
return sum((a*b) for a, b in zip(v1, v2))
def mag(v):
"""This function computes magnitude of two vectors."""
return math.sqrt(dotproduct(v, v))
def angle(v1, v2):
"""This function computes angle between two vectors."""
return (np.arccos(dotproduct(v1, v2) / (mag(v1) * mag(v2))))*(180/math.pi)
The angle should be continuously increasing but it fluctuating.