Skip to content

halfedges

halfedges(F)

Given a triangle mesh with face indices F, returns all oriented halfedges as indices into the vertex array.

The ordering convention for halfedges is the following: [halfedge opposite vertex 0, halfedge opposite vertex 1, halfedge opposite vertex 2]

Parameters:

Name Type Description Default
F (m,3) numpy int array

face index list of a triangle mesh

required

Returns:

Name Type Description
he (m,3,2) numpy int array

halfedge list as per above conventions

Examples:

# Sample mesh
v = np.array([[0.0,0.0],[1.0,0.0],[0.0,1.0]])
f = np.array([[0,1,2]],dtype=int)
# Call to halfedges
from gpytoolbox import halfedges
# (Thank you to Lukas Hermann for finding and fixing a typo in this next line)
he = halfedges(f)
Source code in src/gpytoolbox/halfedges.py
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def halfedges(F):
    """Given a triangle mesh with face indices F, returns all oriented halfedges
    as indices into the vertex array.

    The ordering convention for halfedges is the following:
    [halfedge opposite vertex 0,
     halfedge opposite vertex 1,
     halfedge opposite vertex 2]

    Parameters
    ----------
    F : (m,3) numpy int array
        face index list of a triangle mesh

    Returns
    -------
    he : (m,3,2) numpy int array
        halfedge list as per above conventions

    Examples
    --------
    ```python
    # Sample mesh
    v = np.array([[0.0,0.0],[1.0,0.0],[0.0,1.0]])
    f = np.array([[0,1,2]],dtype=int)
    # Call to halfedges
    from gpytoolbox import halfedges
    # (Thank you to Lukas Hermann for finding and fixing a typo in this next line)
    he = halfedges(f)
    ```

    """

    assert F.shape[0] > 0
    assert F.shape[1] == 3

    he = np.block([[[F[:,1][:,None], F[:,2][:,None]]],
        [[F[:,2][:,None], F[:,0][:,None]]],
        [[F[:,0][:,None], F[:,1][:,None]]]]).transpose((1,0,2))
    return he