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)