ladybug_geometry.geometry2d.mesh module

2D Mesh

class ladybug_geometry.geometry2d.mesh.Mesh2D(vertices, faces, colors=None)[source]

Bases: MeshBase

2D Mesh object.

Parameters:
  • vertices – A list or tuple of Point2D objects for vertices.

  • faces – A list of tuples with each tuple having either 3 or 4 integers. These integers correspond to indices within the list of vertices.

  • colors – An optional list of colors that correspond to either the faces of the mesh or the vertices of the mesh. Default is None.

Properties:
  • vertices

  • faces

  • colors

  • is_color_by_face

  • min

  • max

  • center

  • area

  • centroid

  • face_areas

  • face_centroids

  • face_area_centroids

  • face_vertices

  • vertex_connected_faces

  • edges

  • naked_edges

  • internal_edges

  • non_manifold_edges

ToString()

Overwrite .NET ToString.

duplicate()

Get a copy of this object.

classmethod from_dict(data)[source]

Create a Mesh2D from a dictionary.

Parameters:

data – A python dictionary in the following format

{
    "type": "Mesh2D",
    "vertices": [(0, 0), (10, 0), (0, 10)],
    "faces": [(0, 1, 2)],
    "colors": [{"r": 255, "g": 0, "b": 0}]
}
classmethod from_face_vertices(faces, purge=True)[source]

Create a mesh from a list of faces with each face defined by Point2Ds.

Parameters:
  • faces – A list of faces with each face defined as a list of 3 or 4 Point2D.

  • purge – A boolean to indicate if duplicate vertices should be shared between faces. Default is True to purge duplicate vertices, which can be slow for large lists of faces but results in a higher-quality mesh with a smaller size in memory. Note that vertices are only considered duplicate if the coordinate values are equal to one another within floating point tolerance. To remove duplicate vertices within a specified tolerance other than floating point, the from_purged_face_vertices method should be used instead.

classmethod from_grid(base_point=Point2D(0.00, 0.00), num_x=1, num_y=1, x_dim=1, y_dim=1, generate_centroids=True)[source]

Initialize a Mesh2D from parameters that define a grid.

Parameters:
  • base_point – The base point from which the mesh grid will be generated. Default is (0, 0).

  • num_x – An integer for the number of mesh cells to generate in the x direction. Default is 1.

  • num_y – An integer for the number of mesh cells to generate in the y direction. Default is 1.

  • x_dim – The x dimension of the grid cells as a number. Default is 1.

  • y_dim – The y dimension of the grid cells as a number. Default is 1.

  • generate_centroids – Set to True to have the face centroids generated alongside the grid of vertices, which is much faster than having them generated upon request as they typically are. However, if you have no need for the face centroids, you would save memory by setting this to False. Default is True.

classmethod from_polygon_grid(polygon, x_dim, y_dim, generate_centroids=True)[source]

Initialize a gridded Mesh2D from a Polygon2D.

Note that this gridded mesh will usually not completely fill the polygon. Essentially, this method generates a grid over the domain of the polygon and then removes any points that do not lie within the polygon.

Parameters:
  • polygon – A Polygon2D object.

  • x_dim – The x dimension of the grid cells as a number.

  • y_dim – The y dimension of the grid cells as a number.

  • generate_centroids – Set to True to have the face centroids generated alongside the grid of vertices, which is much faster than having them generated upon request as they typically are. However, if you have no need for the face centroids, you would save memory by setting this to False. Default is True.

classmethod from_polygon_triangulated(boundary_polygon, hole_polygons=None)[source]

Initialize a triangulated Mesh2D from a Polygon2D.

The triangles of the mesh faces will always completely fill the shape defines by the input boundary_polygon with holes subtracted from it.

Parameters:
  • boundary_polygon – A Polygon2D object representing the boundary of the shape.

  • hole_polygons – Optional list of Polygon2D objects representing holes within the boundary_polygon.

classmethod from_purged_face_vertices(faces, tolerance)[source]

Create a mesh from a list of faces with each face defined by Point3Ds.

This method is slower than ‘from_face_vertices’ but will result in a mesh with fewer vertices and a smaller size in memory. This method is similar to using the ‘purge’ option in ‘from_face_vertices’ but will result in more shared vertices since it uses a tolerance to check equivalent vertices rather than comparing within floating point tolerance.

Parameters:
  • faces – A list of faces with each face defined as a list of 3 or 4 Point3D.

  • tolerance – A number for the minimum difference between coordinate values at which point vertices are considered equal to one another.

static join_meshes(meshes)[source]

Join an array of Mesh2Ds into a single Mesh2D.

Parameters:

meshes – An array of meshes to be joined into one.

Returns:

A single Mesh2D object derived from the input meshes.

move(moving_vec)

Get a mesh that has been moved along a vector.

Parameters:

moving_vec – A Vector with the direction and distance to move the mesh.

reflect(normal, origin)

Get a mesh reflected across a plane with the input normal vector and origin.

Parameters:
  • normal – A Vector representing the normal vector for the plane across which the mesh will be reflected. THIS VECTOR MUST BE NORMALIZED.

  • origin – A Point representing the origin from which to reflect.

remove_faces(pattern)[source]

Get a version of this mesh where faces are removed according to a pattern.

Parameters:

pattern – A list of boolean values denoting whether a face should remain in the mesh (True) or be removed from the mesh (False). The length of this list must match the number of this mesh’s faces.

Returns:

A tuple with two elements

  • new_mesh: A mesh where the faces have been removed according to the input pattern.

  • vertex_pattern: A list of boolean values that corresponds to the original mesh vertices noting whether the vertex is in the new mesh (True) or has been removed from the new mesh (False).

remove_faces_only(pattern)[source]

Get a version of this mesh where faces are removed and vertices are unaltered.

This is faster than the Mesh2D.remove_faces method but will likely result a lower-quality mesh where several vertices exist in the mesh that are not referenced by any face. This may be preferred if pure speed of removing faces is a priority over smallest size of the mesh in memory.

Parameters:

pattern – A list of boolean values denoting whether a face should remain in the mesh (True) or be removed from the mesh (False). The length of this list must match the number of this mesh’s faces.

Returns:

new_mesh – A mesh where the faces have been removed according to the input pattern.

remove_vertices(pattern)[source]

Get a version of this mesh where vertices are removed according to a pattern.

Parameters:

pattern – A list of boolean values denoting whether a vertex should remain in the mesh (True) or be removed from the mesh (False). The length of this list must match the number of this mesh’s vertices.

Returns:

A tuple with two elements

  • new_mesh: A mesh where the vertices have been removed according to the input pattern.

  • face_pattern: A list of boolean values that corresponds to the original mesh faces noting whether the face is in the new mesh (True) or has been removed from the new mesh (False).

rotate(angle, origin)[source]

Get a mesh that is rotated counterclockwise by a certain angle.

Parameters:
  • angle – An angle for rotation in radians.

  • origin – A Point2D for the origin around which the point will be rotated.

scale(factor, origin=None)[source]

Scale a mesh by a factor from an origin point.

Parameters:
  • factor – A number representing how much the mesh should be scaled.

  • origin – A Point representing the origin from which to scale. If None, it will be scaled from the World origin (0, 0).

to_dict()[source]

Get Mesh2D as a dictionary.

triangulated()[source]

Get a version of this Mesh2D where all quads have been triangulated.

property area

The area of the entire mesh.

property center

A Point2D for the center of the bounding rectangle around this geometry.

property centroid

The centroid of the mesh as a Point2D (aka. center of mass).

Note that the centroid is more time consuming to compute than the center (or the middle point of the bounding rectangle). So the center might be preferred over the centroid if you just need a rough point for the middle of the mesh.

property colors

Get or set a list of colors for the mesh. Will be None if no colors assigned.

property edges

“Tuple of all edges in this Mesh3D as LineSegment3D objects.

property face_area_centroids

Tuple of face area centroids that aligns the faces property.

These Point3Ds are are the area centroids of the faces, which come from considering the surface of each quad face as having constant density.

The area centroid is more intensive to compute compared to the vertex centroid available through the face_centroids property. Moreover, the area centroid is equal to the vertex centroid for triangles and fairly close to the vertex centroid for convex quad faces with moderate aspect ratios. Therefore, this property is most useful when working with meshes containing concave quad faces or quads with extreme aspect ratios.

property face_areas

A tuple of face areas that parallels the faces property.

property face_centroids

Tuple of face centroids that aligns the faces property.

These Point3Ds are are the vertex centroids of the faces, which come from considering each quad face as being empty but having equal mass at each vertex.

Because such vertex centroids are computed as the mean of the coordinate values, they are fast to compute and a good property to use when generating test points that align large meshes predominantly containing triangles and/or convex quad faces. For meshes containing concave quad faces, the face_area_centroids may produce a more desirable result.

property face_edges

List of polylines with one Polyline2D for each face.

This is faster to compute compared to the edges and results in effectively the same type of wireframe visualization.

property face_vertices

Tuple of mesh faces with each face defined as a tuple of Point3Ds.

property faces

Tuple of all faces in the mesh.

property internal_edges

“Tuple of all internal edges in this Mesh3D as LineSegment3D objects.

Internal edges are shared between two faces in the mesh.

property is_color_by_face

Boolean for whether colors are face-by-face (True) or vertex-by-vertex (False)

When colors are assigned to the mesh, this property is linked to the colors and cannot be set. However, when no colors are assigned, it can be set because it affects how the mesh is translated to external interfaces. In such cases, this property notes whether the mesh will be translated in a format that can accept face-by-face colors. Default is False when no colors are assigned.

property max

A Point2D for the maximum bounding rectangle vertex around this geometry.

property min

A Point2D for the minimum bounding rectangle vertex around this geometry.

property naked_edges

“Tuple of all naked edges in this Mesh3D as LineSegment3D objects.

Naked edges belong to only one face in the mesh (they are not shared between faces).

property non_manifold_edges

“Tuple of all non-manifold edges in this mesh as LineSegment3D objects.

Non-manifold edges are shared between three or more faces.

property vertex_connected_faces

Tuple with a tuple for each vertex that lists the indexes of connected faces.

property vertices

Tuple of all vertices in this geometry.