我在一个平面上有三个点,在另一个平面上有三个点。我想要平面之间的角度,所以我用点来做向量,叉积来求法向量,点积,除以大小和倒数cos来求角度。你知道吗
我期望45或0.785398是平面法线与点之间的夹角。我得到0.6154797086703875
我的逻辑一定有问题,有人能帮忙吗?非常感谢。你知道吗
import numpy as np
"""
y axis up page
x axis to the right on page
z axis towards user out of page
point1 -1,1,0
point2 1,1,0
point3 1,1,1
so horizontal plane at y=1
point4 0,0,0
point5 1,1,0
point6 1,1,1
plane at 45 degrees meeting other plane at 1,1,n
"""
#use points to make vectors
#point2 - point1
vx1 = 2#1--1
vy1 = 0#1-1
vz1 = 0#0-0
#point3 - point1
vx2 = 2#1--1
vy2 = 0#1-1
vz2 = 1#1-0
#cross product to find normal
plane1 = np.cross([vx1,vy1,vz1],[vx2,vy2,vz2])
#use points to make vectors
#point5 - point4
vx1 = 1#1-0
vy1 = 1#1-0
vz1 = 0#0-0
#point6 - point4
vx2 = 1#1-0
vy2 = 1#1-0
vz2 = 1#1-0
#cross product to find normal
plane2 = np.cross([vx1,vy1,vz1],[vx2,vy2,vz2])
#angle between the two normals
#dot product
ang = np.dot(plane1,plane2)
#divide by magnitude of vectors
ang = ang / (np.sqrt((vx1*vx1)+(vy1*vy1)+(vz1*vz1))*np.sqrt((vx2*vx2)+(vy2*vy2)+(vz2*vz2)))
#inverse cos to find angle
ang = np.arccos(ang)
#should be 45 or 0.785398
print("Angle calculated",ang)
if (ang < 95) and (ang > 85):
print("RIGHT ANGLE")
else:
print("OTHER ANGLE")
使用
np.linalg.norm
:如注释中所述,错误在于使用了错误的向量进行规范化。你知道吗
我想补充一点,Binet-Cauchy在这里也可以工作,而且比使用交叉积快得多。你知道吗
相关问题 更多 >
编程相关推荐