Beispiel #1
0
    def face_flatness(self, fkey, maxdev=0.02):
        """Compute the flatness of the mesh face.

        Parameters
        ----------
        fkey : int
            The identifier of the face.
        maxdev : float, optional
            A maximum value for the allowed deviation from flatness.
            Default is ``0.02``.

        Returns
        -------
        float
            The flatness.

        Notes
        -----
        Flatness is computed as the ratio of the distance between the diagonals
        of the face to the average edge length. A practical limit on this value
        realted to manufacturing is 0.02 (2%).

        Warnings
        --------
        This method only makes sense for quadrilateral faces.
        """
        vertices = self.face_vertices(fkey)
        f = len(vertices)
        points = self.vertices_attributes('xyz', keys=vertices)
        lengths = [distance_point_point(a, b) for a, b in pairwise(points + points[:1])]
        length = sum(lengths) / f
        d = distance_line_line((points[0], points[2]), (points[1], points[3]))
        return (d / length) / maxdev
Beispiel #2
0
def flatness(vertices, faces, maxdev=0.02):
    """Compute mesh flatness per face.

    Parameters
    ----------
    vertices : list
        The vertex coordinates.
    faces : list
        The face vertices.
    maxdev : float, optional
        A maximum value for the allowed deviation from flatness.
        Default is ``0.02``.

    Returns
    -------
    dict
        For each face, a deviation from *flatness*.

    Notes
    -----
    The "flatness" of a face is expressed as the ratio of the distance between
    the diagonals to the average edge length. For the fabrication of glass panels,
    for example, ``0.02`` could be a reasonable maximum value.

    Warning
    -------
    This function only works as expected for quadrilateral faces.

    See Also
    --------
    * :func:`compas.geometry.mesh_flatness`

    """
    dev = []
    for face in faces:
        points = [vertices[index] for index in face]
        lengths = [
            distance_point_point(a, b)
            for a, b in window(points + points[0:1], 2)
        ]
        l = sum(lengths) / len(lengths)
        d = distance_line_line((points[0], points[2]), (points[1], points[3]))
        dev.append((d / l) / maxdev)
    return dev
Beispiel #3
0
def mesh_flatness(mesh, maxdev=1.0):
    """Compute mesh flatness per face.

    Parameters
    ----------
    mesh : Mesh
        A mesh object.
    maxdev : float, optional
        A maximum value for the allowed deviation from flatness.
        Default is ``1.0``.

    Returns
    -------
    dict
        For each face, a deviation from *flatness*.

    Notes
    -----
    The "flatness" of a face is expressed as the ratio of the distance between
    the diagonals to the average edge length. For the fabrication of glass panels,
    for example, ``0.02`` could be a reasonable maximum value.

    Warnings
    --------
    This function only works as expected for quadrilateral faces.

    """
    dev = []
    for fkey in mesh.faces():
        points = mesh.face_coordinates(fkey)
        if len(points) == 3:
            dev.append(0.0)
        else:
            lengths = [
                distance_point_point(a, b)
                for a, b in window(points + points[0:1], 2)
            ]
            length = sum(lengths) / len(lengths)
            d = distance_line_line((points[0], points[2]),
                                   (points[1], points[3]))
            dev.append((d / length) / maxdev)
    return dev
Beispiel #4
0
def face_curvatures(mesh):
    """Curvatures of the mesh quad faces as dict face: face curvature.
	Curvature of a face = distance between diagonals / mean diagonal length.

	Parameters
	----------
	mesh : Mesh
		A mesh.

	Returns
	-------
	face_curvature_dict: dict
		Dictionary of curvatures per face {face: face curvature}. None if vertex is not a quad.

	Raises
	------
	-

	"""

    face_curvature_dict = {}
    for fkey in mesh.faces():
        if len(mesh.face_vertices(fkey)) == 4:
            u, v, w, x = [
                mesh.vertex_coordinates(vkey)
                for vkey in mesh.face_vertices(fkey)
            ]
            face_curvature_dict[fkey] = distance_line_line(
                (u, w), (v, x)) / (distance_point_point(u, w) +
                                   distance_point_point(v, x)) * 2
        elif len(mesh.face_vertices(fkey)) == 3:
            face_curvature_dict[fkey] = 0
        else:
            face_curvature_dict[fkey] = None

    return face_curvature_dict