[英]angle between two vectors by using simple numpy or math in Python?
i am trying to find out dihedral between two planes i have all the coordinates and i calculated vectors but the last step is giving problem, my last step is to find the angle between the vectors. 我试图找出两个平面之间的二面角,我拥有所有坐标,并且我计算了向量,但是最后一步给了问题,我的最后一步是找到向量之间的角度。 here is my code
这是我的代码
V1= (x2-x1,y2-y1,z2-z1)
V2= (x3-x2,y3-y2,z3-z2)
V3= (x4-x3,y4-y3,z4-z3)
V4= numpy.cross(V1,V2)
V5= numpy.cross(V2,V3)
dihedral=math.acos(V4.V5)
print dihedral
please tell me if this is right? 请告诉我这是否正确? i know coordinates for 4 points from which i made 3 vectors V1, V2, V3 and then i did cross product to get 2 vectors , now i want to find angle between these vectors.
我知道4个点的坐标,从中我得到3个向量V1,V2,V3,然后我做叉积运算得到2个向量,现在我想找到这些向量之间的夹角。
Using cross products of vectors to calculate angles will only work if the vectors have unit length. 仅当向量具有单位长度时,才可以使用向量的叉积来计算角度。 You should normalize them first, eg
您应该首先将它们标准化,例如
V4 = V4/np.sqrt(np.dot(V4,V4))
Furthermore, I think you meant to write math.acos(np.dot(V4,V5))
for math.acos(V4.V5)
. 此外,我认为您打算为
math.acos(V4.V5)
编写math.acos(np.dot(V4,V5))
math.acos(V4.V5)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.