コード例 #1
0
def test_line_sdl_1D(direction, length):
    """
    Tests if the result will produce a 1D line if a 1D point is passed in.
    """
    start1D = [0.0]
    ln = line_sdl(start1D, direction, length)
    assert ln == ([-1.0], [1.0])
コード例 #2
0
    def draw_vector_field(self, field, color, uniform, scale, width=0.5):
        """
        Draws a vector field on a mesh.

        It assumes the field and the mesh faces have the same keys.
        """
        _lines = []
        lines = []
        mesh = self.mesh

        for fkey in range(field.size()):
            vector = field[fkey]
            length = scale
            if not uniform:
                length = length_vector(vector) * scale
            _lines.append(line_sdl(mesh.face_centroid(fkey), vector, length))

        _lines = [line for line in map(line_tuple_to_dict, _lines)]

        for line in _lines:
            line["width"] = width
            line["color"] = color

        lines.extend(_lines)

        self.draw_lines(lines)
コード例 #3
0
    def plot_vector_field_lines(self, mesh, vector_field, color, uniform,
                                scale):
        """
        Plots a vector field as lines.

        Parameters
        ----------
        mesh : `compas.datastructures.Mesh`
            A COMPAS mesh with 3D vertices.
        vector_field : `directional_clustering.fields.VectorField`
            The vector field to plot.
        color : `rbg`
            The color of the line. Refer to `plotly.graph_objects.scatter3d.Line`
            for more options.
        uniform : `bool`
            Sets same length equals to `scale` to all lines if `True`.
        scale : `float`
            Scales vector lines.
        """
        field = vectors_dict_to_array(vector_field, mesh.number_of_faces())
        lines = []

        # get lines
        rows, _ = field.shape
        for fkey in range(rows):
            vector = field[fkey]
            vector = vector.tolist()

            if uniform:
                vec_length = scale
            else:
                vec_length = length_vector(vector) * scale

            pt = mesh.face_centroid(fkey)
            lines.append(line_sdl(pt, vector, vec_length))

        # "s" is shorthand for start, "e" is shorthand for end
        s_x, s_y, s_z, e_x, e_y, e_z = lines_to_start_end_xyz(lines)

        # "cse" is shorthand for connected start and end
        cse_x, cse_y, cse_z = lines_start_end_connect(s_x, s_y, s_z, e_x, e_y,
                                                      e_z)

        # add lines to plot
        self.add_trace(
            go.Scatter3d(x=cse_x,
                         y=cse_y,
                         z=cse_z,
                         mode='lines',
                         line=dict(width=2, color=color),
                         opacity=1))
コード例 #4
0
def test_line_sdl_one_side(start, direction, length):
    """
    Tests if a line is create correctly with both sides = False.
    """
    ln = line_sdl(start, direction, length, False)
    assert ln == (start, [1.0, 1.0, 0.0])
コード例 #5
0
def test_lines_sdl_no_length(start, direction):
    """
    Tests if a type error is raised when a line_sdl has no length as input.
    """
    with pytest.raises(TypeError):
        line_sdl(start, direction)
コード例 #6
0
def test_line_sdl_both_sides(start, direction, length):
    """
    Tests if a line is created correctly with both sides = True.
    """
    ln = line_sdl(start, direction, length, True)
    assert ln == ([-1.0, 1.0, 0.0], [1.0, 1.0, 0.0])