polynomials_on_simplices.geometry.mesh.triangle_mesh module

Calculations on a triangle mesh.

centroid(t, v)[source]

Compute the centroid of a triangle mesh (the centroid is the center of gravity if all triangles have uniform and identical density).

Parameters:
  • t – List of triangle indices in the mesh. Size (n, 3) where n is the number of triangles.
  • v – List of vertices in the mesh. Size (m, 3) where m is the number of vertices.
Returns:

The centroid of the triangle mesh.

centroids(t, v)[source]

Compute triangle centroids for each triangle in the mesh.

Parameters:
  • t – List of triangle indices in the mesh. Size (n, 3) where n is the number of triangles.
  • v – List of vertices in the mesh. Size (m, 3) where m is the number of vertices.
Returns:

List of triangle centroids.

edge_index(indexed_triangle, edge)[source]

Find the index of an edge in a triangle.

Note

The i:th edge of a triangle is the edge opposite to the i:th vertex, i in {0, 1, 2}.

Parameters:
  • indexed_triangle (Length 3 array of ints) – Indices for the three vertices in the triangle.
  • edge (Pair of ints) – Indices for the two vertices of the edge.
Returns:

Index (in {0, 1, 2}) of the edge in the triangle.

Return type:

int

Examples

>>> edge_index([0, 1, 2], (0, 1))
2
>>> edge_index([3, 8, 11], (3, 11))
1
get_num_vertices(triangles)[source]

Get the number of vertices in a triangulation.

Parameters:triangles – List of triangles in the triangulation.
Returns:Number of vertices in the triangulation.
has_consistent_orientation(triangles)[source]

Check if all triangles in a triangulation have the same orientation.

Parameters:triangles – List of triangles in the triangulation.
Returns:True if all the triangles have the same orientation. False otherwise.
has_same_edge_orientation(triangles, tri_idx, edge)[source]

Check if a triangle and its neighbour across a given edge have the same orientation.

Parameters:
  • triangles – List of triangles in the triangulation.
  • tri_idx – Triangle we originate from.
  • edge – Edge index in {0, 1, 2}. We compare the orientation with the triangle across this edge.
Returns:

True if the orientation is the same, or if the triangle don’t have any neighbour across the given edge. False otherwise.

has_same_orientation(triangle1, triangle2)[source]

Check if two neighbouring indexed triangles have the same orientation.

Parameters:
  • triangle1 – First indexed triangle (list of three vertex indices).
  • triangle2 – Second indexed triangle (list of three vertex indices).
Returns:

True if the orientation is the same, False otherwise.

has_vertex(t, tri, vertex)[source]

Whether or not a triangle contains a specific vertex.

Parameters:
  • t – List of triangle indices in the mesh. Size (n, 3) where n is the number of triangles.
  • tri – Triangle index.
  • vertex – Vertex index.
Returns:

True if the triangle contains the vertex, otherwise False.

neighbour(t, i, j)[source]

Get the triangle edge neighbour of a triangle.

Parameters:
  • t – List of triangle indices in the mesh. Size (n, 3) where n is the number of triangles.
  • i – Triangle index.
  • j – Edge index.
Returns:

Index of triangle neighbouring triangle i along edge j, or None if no neighbour exists.

normals(t, v)[source]

Compute triangle normals for each triangle in the mesh.

Parameters:
  • t – List of triangle indices in the mesh. Size (n, 3) where n is the number of triangles.
  • v – List of vertices in the mesh. Size (m, 3) where m is the number of vertices.
Returns:

List of normalized triangle normals.

opposite_vertex(t, tri, edge)[source]

Get the opposite vertex of a triangle across one of its edges.

Parameters:
  • t – List of triangle indices in the mesh. Size (n, 3) where n is the number of triangles.
  • tri – Triangle index.
  • edge – Edge index.
Returns:

Index of vertex opposite edge j of triangle i, or None if no neighbour exists.

swap_orientation(triangles, tri_idx)[source]

Change the orientation of a triangle.

Parameters:
  • triangles – List of triangles in the triangulation.
  • tri_idx – Triangle which should have its orientation swapped.
Returns:

Nothing.

vertex_normals(t, v, weight='area')[source]

Compute vertex normals for each vertex in the mesh by computing a weighted sum of the triangle normals surrounding each vertex.

The area weighted vertex normal arises when you identify the vertex normal with the volume gradient with respect to the vertex coordinates.

Parameters:
  • t – List of triangle indices in the mesh. Size (n, 3) where n is the number of triangles.
  • v – List of vertices in the mesh. Size (m, 3) where m is the number of vertices.
  • weight (str) –

    Weight factor used when computing the weighted sum of triangle normals. Possible values:

    • None: 1 is used as weight for each triangle normal.
    • ”area”: Each triangle normal is weighted with the area of the triangle.
    • ”angle”: Each triangle normal is weighted with the triangle angle at the vertex.
Returns:

List of normalized vertex normals.

vertex_normals_cotangent(t, v)[source]

Compute a normal at each vertex in the mesh using the cotan formula. This expression arises when you identify the vertex normal with the surface area gradient with respect to the vertex coordinates.

vertex_position(indexed_triangle, vertex_index)[source]

Position of a specific vertex in an indexed triangle.

Parameters:
  • indexed_triangle – List of three vertex indices.
  • vertex_index – Vertex index to look for in the triangle.
Returns:

0, 1 or 2 depending on whether the vertex is the first, second or third vertex in the triangle. Returns None if the vertex does not exist in the triangle.

vertices(tri, vertex_list)[source]

Get the vertices of a triangle in the mesh.

Parameters:
  • tri – Triangle (list of 3 vertex indices).
  • vertex_list – List of vertices in the mesh. Size (m, dim) where m is the number of vertices.
Returns:

3 by dim matrix containing the triangle vertices as row vectors.