Skip to content

halfedge_lengths_squared

halfedge_lengths_squared(V, F)

Given a triangle mesh V,F, returns the lengths of all halfedges, squared. The reason to work with squared lengths instead of just lengths is that lengths are computed as squared lengths, and then often used as squared lengths, and thus keeping track of the squared lengths circumvents a lossy square root followed by a square.

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
V (n,d) numpy array

vertex list of a triangle mesh

required
F (m,3) numpy int array

face index list of a triangle mesh

required

Returns:

Name Type Description
l_sq (m,3) numpy array

squared lengths of halfedges

See Also

halfedge_lengths.

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 halfedge_lengths_squared
from gpytoolbox import halfedge_lengths_squared
l_sq = halfedge_lengths_squared(v,f)
Source code in src/gpytoolbox/halfedge_lengths_squared.py
 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
43
44
45
46
47
48
49
50
51
52
53
def halfedge_lengths_squared(V,F):
    """Given a triangle mesh V,F, returns the lengths of all halfedges, squared.
    The reason to work with squared lengths instead of just lengths is that
    lengths are computed as squared lengths, and then often used as squared
    lengths, and thus keeping track of the squared lengths circumvents a
    lossy square root followed by a square.

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

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

    Returns
    -------
    l_sq : (m,3) numpy array
        squared lengths of halfedges

    See Also
    --------
    halfedge_lengths.

    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 halfedge_lengths_squared
    from gpytoolbox import halfedge_lengths_squared
    l_sq = halfedge_lengths_squared(v,f)
    ```

    """

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

    he = halfedges(F)

    edge_vectors = V[he[:,:,1],:] - V[he[:,:,0],:]
    return np.sum(edge_vectors**2, axis=-1)