# Tetrahedron orientation

I am developing a software that needs to interact with a mesh processing program, using tetrahedral meshes, however I am finding difficulties in this.

The program requires all tetrahedrons to have right handed orientation, and this is not the hard part, as given a list of vertices $$\{ v_0, v_1, v_2, v_3 \}$$, I need to check that

$$h := ( \; (v_0 - v_1) \times (v_0 - v_2) \;) \cdot (v_0 - v_3) > 0$$

In case $$h < 0$$, any odd permutation will be correct, as $$\{ v_0, v_1, v_3, v_2 \}$$.

The problem is that, as they told me, the program requires that all faces are oriented with the right hand rule.

This requirement puzzles me, and I do not understand it completely.

Can anyone point me in the right direction?

### Code

class tetrahedron:
def __init__(self, vertices):
# compute handedness
c = numpy.cross(vertices.coords-vertices.coords, vertices.coords-vertices.coords)
h = numpy.inner( c, vertices.coords-vertices.coords )

# vertex indices with correct right-handed orientation
if h > 0:
self.vertices = vertices
else:
s = "old h = %f" % (h)
# swap last two vertices
self.vertices = [vertices, vertices, vertices, vertices]
vertices = self.vertices
c = numpy.cross(vertices.coords-vertices.coords, vertices.coords-vertices.coords)
h = numpy.inner( c, vertices.coords-vertices.coords )
s = s + " new h = %f" % (h)
print(s)


### Updated Code

I have updated my code according to the suggestions, but apparently faces are still a problem, the error it gives is

Two elements connect to the same side of the shared element face. Coordinates: 12.3669, -61.573, 81.0725


My code is now as follows:

import numpy

def handedness(vertices):
c = numpy.cross(vertices.coords-vertices.coords, \
vertices.coords-vertices.coords)
h = numpy.inner( c, vertices.coords-vertices.coords )
return h

class tetrahedron:
def __init__(self, vertices):
h = handedness(vertices)

if h > 0:
self.vertices = vertices
else:
s = "old h = %f" % (h)
# swap last two vertices
self.vertices = [vertices, vertices, vertices, vertices]
vertices = self.vertices
h = handedness(self.vertices)
s = s + " new h = %f" % (h)
print(s)


## 1 Answer

This refers to the order of vertices within a face. Typically in 3D graphics, faces are wound counterclockwise, so that if you're looking from outside of the tetrahedron/mesh, all the front faces will have their vertices in counterclockwise order. (See here and here for more explanation.) This is a "right-hand rule" in that if the fingers of your right hand curl in the winding direction of the vertices, then your thumb points toward the outside of the mesh.

• Thanks, so how can I ensure that a tet has the right face orientation? I am using the above to check the handedness of a solid (a tet), should I check all faces? So checking for each face $j$, ie, $(-1)^{j}[v_{0},\ldots ,v_{j-1},v_{j+1},\ldots ,v_{n}]$ some property? Is there a closed formula? – senseiwa Oct 24 '20 at 13:20
• I would need to know more about the program and the context of this requirement. I would expect that given a tet in the correct orientation that it would automatically generate the correct faces. The requirement might refer to some other faces, e.g. the faces of a volume which is being subdivided and filled with tetrahedra, etc. – Nathan Reed Oct 24 '20 at 22:12
• Thanks for the answer. I've included my code for a tet (maybe I am doing something wrong and I don't see it), the software I am interfacing with is this, here is the link to the documentation, where tets are on page 38. I thought my code would be sufficient, but writing a mesh file with vertices and tets will raise an error on faces. Of course a single tet works. – senseiwa Oct 25 '20 at 7:47
• Hmm. Looking at your tet handedness equation again, I think you have a sign error - the vectors should be like $v_i - v_0$ rather than $v_0 - v_i$. In other words, all the vectors should be based at $v_0$ and pointing toward the other vertices. That's consistent with the tet diagram on page 38, I think. – Nathan Reed Oct 25 '20 at 21:29
• Sorry, I don't think I can help further with the information available. The error message seems to suggest that the set of tets might be duplicated, or contain overlapping tets reusing the same faces somehow. – Nathan Reed Oct 26 '20 at 17:08