1

I hope to be as clear as possible. I'm trying to implement a function that, given two tetrahedra, checks if they intersect with each other. I am working with python and the only library I am using is NumPy. To describe a tetrahedron I use its 4 vertices which are each described by coordinates [x, y, z].

vertex = [x, y, z]

tetrahedra = [vertex 1,vertex 2,vertex 3,vertex 4]

This is the reasoning I want to use:

  • A tetrahedron is nothing more than a region defined by inequalities.
  • These inequalities are described by the planes containing one face of the tetrahedron.
  • So given the inequalities of the two tetrahedra, and putting them in a system, if this system admits a solution then there is an intersection.

This is my function:

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

In this case I have solved the system of inequalities using cvxpy and I have verified the particular case in which the two tetrahedra have a common face. However this code does not cover the cases in which the touch occurs between vertices or between face-vertex, side-vertex, side-side. That is all those situations in which there is no real interpenetration, but there is a touch between the two tetrahedra.

So what I'm asking is if there is a way to verify the interpenetration between two tetrahedra, including this case too? Thanks in advance!

gmarco97
  • 35
  • 8
  • 1
    Not really an implementation question, but you should be able to use [this method](http://steve.hollasch.net/cgindex/geometry/ptintet.html) to determine if the points of one are on the surface of the other or vice-versa by if their determinants are 0 (or close to zero, since floating point errors will likely crop up.) – Daniel F Nov 24 '20 at 11:12
  • Daniel, thanks for the advice but this technique does not rule out the existence of an intersection between the two tetrahedra, as a vertex can lie on the "perimeter" of a tetrahedron even if the polyhedron it is part of actually generates an intersection. Or no vertex can belong to the other tetrahedron but the intersection exists. However it might be an idea. – gmarco97 Nov 24 '20 at 17:39
  • 1
    While I think the method Daniel posted is the way to go, you can also check line-plane intersections, edge of a tetrahedron with faces of the other, and testing if that intersection lies inside the face – Ripi2 Nov 24 '20 at 19:06
  • I also had this intuition but subsequently I came to the following conclusion: That is, a tetrahedron is entirely described by a system of 4 inequalities with 3 unknowns, where each inequality is composed of the plane containing a face. It goes without saying that by solving the system of inequalities that describe the two tetrahedra "or I verify the existence of common points" I can verify the existence of an interpenetration. – gmarco97 Nov 24 '20 at 20:38
  • I used this approach in the code above. However, not being able to exclude the "perimeter" from the set of solutions of the Operations Research problem, I wanted to know if there was another way to solve a system of inequalities without using cvxpy. – gmarco97 Nov 24 '20 at 20:44

1 Answers1

0

In the end I followed the advice of DanielF and Ripi2, as with my method I could not get out of it.

OBJECTIVE: Given two tetrahedra to verify if there is an interpenetration between the two.

SOLUTION: Taken a tetrahedron, represented by 4 vertices,

tr = [[v1,1], [v2,2], [v3,4], [v4,4]]
vi = [x, y, z] with i = 1, 2, 3, 4
  1. I verify a possible equality between the two tetrahedra.

  2. Itero on the vertices of one of the two tetrahedra, checking if the vertex "of index i" is inside the other tetrahedron. If this condition is verified then I can affirm the existence of an interpenetration.

  3. Otherwise, Itero over the remaining vertices "index j = i + 1" and I calculate the director vector passing through the two points for each pair of vertices. I derive the equations that describe the planes, "that is the faces of the tetrahedron in the form (xa + yb + zc + d = 0)" and check if there is a straight plane intersection.

  4. If such intersection exists check if the intersection point is inside the triangle that identifies the face.

  5. If this happens then I calculate the distance between the point of intersection and the point vi, if this distance is less than the distance between the vertex vi and vj then I can say that there is an intersection between the two tetrahedra.

If these checks do not lead to any solution then I do the same check by exchanging the roles of the two tetrahedra and from here I draw my conclusions. I hope I have been as clear as possible and have not created too much confusion.

gmarco97
  • 35
  • 8