# 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[0].coords-vertices[1].coords, vertices[0].coords-vertices[2].coords)
h = numpy.inner( c, vertices[0].coords-vertices[3].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[0], vertices[1], vertices[3], vertices[2]]
vertices = self.vertices
c = numpy.cross(vertices[0].coords-vertices[1].coords, vertices[0].coords-vertices[2].coords)
h = numpy.inner( c, vertices[0].coords-vertices[3].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[1].coords-vertices[0].coords, \
vertices[2].coords-vertices[0].coords)
h = numpy.inner( c, vertices[3].coords-vertices[0].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[0], vertices[1], vertices[3], vertices[2]]
vertices = self.vertices
h = handedness(self.vertices)
s = s + " new h = %f" % (h)
print(s)

• 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
• 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