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

        Parameters
        ----------
        fkey : int
            The identifier of the face.

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

        Note
        ----
        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%).

        Warning
        -------
        This method only makes sense for quadrilateral faces.
        """
        vertices = self.face_coordinates(fkey)
        face = range(len(self.face_vertices(fkey)))
        return flatness(vertices, [face])[0]
Beispiel #2
0
def callback(k, args):
    for index in range(len(vertices_1)):
        if index in fixed:
            vertices_1[index][2] = 0

    if k % 5 == 0:
        dev = flatness(vertices_1, faces, 0.02)
        conduit.colors = [
            FromArgb(*i_to_rgb(dev[i])) for i in range(len(faces))
        ]
        conduit.redraw()
Beispiel #3
0
def draw_interface(vertices, faces, maxdev):
    # don't refresh viewport
    rs.EnableRedraw(False)
    # compute level of flatness
    flat_vals = flatness(vertices, faces, maxdev)

    srfs = []
    for i, face in enumerate(faces):
        # vertex coordinates for face
        pts = [vertices[key] for key in face]
        # create Rhino surface
        srfs.append(rs.AddSrfPt(pts))
        # color surface based on flatness
        rgb = i_to_rgb(flat_vals[i])
        rs.ObjectColor(srfs[-1], rgb)

    rs.AddObjectsToGroup(srfs, rs.AddGroup())
    # refresh viewport
    rs.EnableRedraw(True)
Beispiel #4
0
            vertices_1[index][2] = 0

    if k % 5 == 0:
        dev = flatness(vertices_1, faces, 0.02)
        conduit.colors = [
            FromArgb(*i_to_rgb(dev[i])) for i in range(len(faces))
        ]
        conduit.redraw()


with conduit.enabled():
    planarize_faces(vertices_1, faces, kmax=500, callback=callback)

# compute the *flatness*

dev0 = flatness(vertices_0, faces, 0.02)
dev1 = flatness(vertices_1, faces, 0.02)

# draw the original

compas_rhino.mesh_draw_faces(mesh,
                             layer='mesh_start',
                             clear_layer=True,
                             color={
                                 fkey: i_to_rgb(dev0[index])
                                 for index, fkey in enumerate(mesh.faces())
                             })

# draw the result

for key, attr in mesh.vertices(True):