【体】两空间向量的夹角

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import numpy as np

def angle(ab, cd):
point_a, point_b = ab
point_c, point_d = cd

L_ab = np.sqrt((point_b-point_a).dot(point_b-point_a))
L_cd = np.sqrt((point_d-point_c).dot(point_d-point_c))

cos_angle = (point_b-point_a).dot(point_d-point_c)/(L_ab*L_cd)

angle = np.arccos(cos_angle)
angle2 = angle*360/2/np.pi

return angle2

a = np.array([0,0,0])
b = np.array([0,1,0])
c = np.array([1,0,0])

print(angle([b, a], [a, c]))
0%