<p>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 <a href="https://www.khronos.org/opengl/wiki/Face_Culling#Winding_order" rel="nofollow noreferrer">here</a> and <a href="https://www.gamasutra.com/view/news/126352/Opinion_Backface_Culling_101.php" rel="nofollow noreferrer">here</a> for more explanation.) This is a &quot;right-hand rule&quot; 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.</p>

CC BY-SA 4.0
2020-10-24T13:20:47.407Z
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
CC BY-SA 4.0
2020-10-24T22:12:04.350Z
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
CC BY-SA 4.0
2020-10-25T07:47:02.667Z
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](https://www.comsol.de/model/comsol-multiphysics-mesh-import-and-export-guide-72351), here is **[the link to the documentation](https://www.comsol.de/model/download/711411/COMSOL_MeshImportExportGuide.pdf)**, 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
CC BY-SA 4.0
2020-10-25T21:29:51.960Z
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
CC BY-SA 4.0
2020-10-26T09:53:27.770Z
Nathan, thank you very much for pointing that out. I've corrected the code but it seems that faces are still a problem. There's something I am missing here, maybe. If you have any idea that would be great. Thanks!
senseiwa
CC BY-SA 4.0
2020-10-26T17:08:04.107Z
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
CC BY-SA 4.0
2020-10-23T19:45:58.633Z
2020-10-23T19:45:58.633Z
Nathan Reed
<p>I am developing a software that needs to interact with a mesh processing program, using tetrahedral meshes, however I am finding difficulties in this.</p>
<p>The program requires all tetrahedrons to have <strong>right handed orientation</strong>, and this is not the hard part, as given a list of vertices <span class="math-container">$\{ v_0, v_1, v_2, v_3 \}$</span>, I need to check that</p>
<p><span class="math-container">$h := ( \; (v_0 - v_1) \times (v_0 - v_2) \;) \cdot (v_0  - v_3) &gt; 0$</span></p>
<p>In case <span class="math-container">$h &lt; 0$</span>, any odd permutation will be correct, as <span class="math-container">$\{ v_0, v_1, v_3, v_2 \}$</span>.</p>
<p>The problem is that, as they told me, the program requires that <strong>all faces are oriented with the right hand rule</strong>.</p>
<p>This requirement puzzles me, and I do not understand it completely.</p>
<p>Can anyone point me in the right direction?</p>
<h3>Code</h3>
<pre><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 &gt; 0:
            self.vertices = vertices
        else:
            s = &quot;old h = %f&quot; % (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 + &quot; new h = %f&quot; % (h)
            print(s)
</code></pre>
<h3>Updated Code</h3>
<p>I have updated my code according to the suggestions, but apparently faces are still a problem, the error it gives is</p>
<pre><code>Two elements connect to the same side of the shared element face. Coordinates: 12.3669, -61.573, 81.0725
</code></pre>
<p>My code is now as follows:</p>
<pre><code>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 &gt; 0:
            self.vertices = vertices
        else:
            s = &quot;old h = %f&quot; % (h)
            # swap last two vertices
            self.vertices = [vertices[0], vertices[1], vertices[3], vertices[2]]
            vertices = self.vertices
            h = handedness(self.vertices)
            s = s + &quot; new h = %f&quot; % (h)
            print(s)
</code></pre>

<mesh>
Tetrahedron orientation
senseiwa
# Tetrahedron orientation

(Asked by: username_0 on 2020-10-23)

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)

```

**Tags:** mesh


---

## 1 answers

### Answer by username_1 on 2020-10-23. Score: 2

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](https://www.khronos.org/opengl/wiki/Face_Culling#Winding_order) and [here](https://www.gamasutra.com/view/news/126352/Opinion_Backface_Culling_101.php) 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.

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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.  
> **username_0**: 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](https://www.comsol.de/model/comsol-multiphysics-mesh-import-and-export-guide-72351), here is **[the link to the documentation](https://www.comsol.de/model/download/711411/COMSOL_MeshImportExportGuide.pdf)**, 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.  
> **username_1**: 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.  
> **username_0**: username_1, thank you very much for pointing that out. I've corrected the code but it seems that faces are still a problem. There's something I am missing here, maybe. If you have any idea that would be great. Thanks!  
> **username_1**: 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.  

---

