我希望尽可能清楚。我试图实现一个函数,给出两个四面体,检查它们是否相交。我正在使用python,我使用的唯一库是NumPy。为了描述一个四面体,我使用它的4个顶点,每个顶点用坐标x,y,z来描述。
vertex = [x, y, z]
tetrahedra = [vertex 1,vertex 2,vertex 3,vertex 4]这就是我想用的理由:
四面体是由inequalities.
这是我的职责:
def IsInterpenetrated(self, tetrahedra):
A= []
B= []
sol= 0
for tr in [self, tetrahedra]:
print("Plane of tetrahedra")
vertexList = tr.vertices
i=0
while i<4:
if handedness(vertexList)>0:
n= numpy.cross(vertexList[1].coords - vertexList[0].coords, vertexList[2].coords - vertexList[0].coords)
else:
n= numpy.cross(vertexList[2].coords - vertexList[0].coords, vertexList[1].coords - vertexList[0].coords)
p0= vertexList[0].coords
d= -(n[0]*p0[0] + n[1]*p0[1] + n[2]*p0[2])
print("normal: ", n , end=" ")
print("termine noto: ",(d))
if len(A) > 3:
j=0
while j<=3:
if numpy.all(-n == A[j]) and -d == B[j]:
sol = 1
j= j+1
A.append(n)
B.append(d)
p0= vertexList[0]
vertexList[0] = vertexList[1]
vertexList[1] = vertexList[2]
vertexList[2] = vertexList[3]
vertexList[3] = p0
i=i+1
A= numpy.array(A)
B= numpy.array(B)
print("\n")
print("Disequazioni:\n")
i=0
for n in A:
print("({0})x + ({1})y + ({2})z + ({3}) > 0".format(n[0],n[1],n[2],B[i]))
i=i+1
print("\n")
x = cvxpy.Variable(3)
prob = cvxpy.Problem(cvxpy.Minimize(0),[A @ x + B >= 0])
prob.solve()
if prob.value == 0 and sol != 1:
return 1
return 0在这种情况下,我用cvxpy解决了不等式系统,并证明了两个四面体具有共同面的特殊情况。但是,这段代码并不涵盖在顶点之间或面-顶点、边-顶点、侧-侧之间发生触摸的情况。在所有这些情况下,没有真正的相互渗透,但两个四面体之间有接触。
所以我要问的是,是否有一种方法来验证两个四面体之间的相互渗透,包括这个例子?提前感谢!
发布于 2020-11-27 08:24:10
最后,我听从了DanielF和Ripi2的建议,就像我的方法无法摆脱它一样。
目的:给出两个四面体,以验证两者之间是否存在相互渗透。
解:取一个四面体,由4个顶点表示,
tr = [[v1,1], [v2,2], [v3,4], [v4,4]]
vi = [x, y, z] with i = 1, 2, 3, 4的存在。
。
如果存在这样的交叉口,请检查识别脸的交集(
。
如果发生这种情况,则计算交点与点vi之间的距离,如果这个距离小于顶点vi与vj之间的距离,则可以说两个四面体之间有一个交点。
如果这些检验不能导致任何解,那么我通过交换两个四面体的作用来做同样的检查,然后从这里得出我的结论。我希望我已经尽可能清楚了,没有造成太多的混乱。
https://stackoverflow.com/questions/64984844
复制相似问题