Example #1
0
def RunCommand(is_interactive):

    if 'AGS' not in sc.sticky:
        compas_rhino.display_message('AGS has not been initialised yet.')
        return

    scene = sc.sticky['AGS']['scene']

    layer = compas_rhino.rs.CurrentLayer()
    layer_name = compas_rhino.rs.GetString("Layer to construct FormDiagram",
                                           layer)
    guids = compas_rhino.get_lines(layer=layer_name)
    if not guids:
        return

    compas_rhino.rs.HideObjects(guids)

    lines = compas_rhino.get_line_coordinates(guids)
    graph = FormGraph.from_lines(lines)

    if not graph.is_planar_embedding():
        compas_rhino.display_message(
            'The graph is not planar. Therefore, a form diagram cannot be created.'
        )
        return

    form = FormDiagram.from_graph(graph)

    scene.purge()
    scene.add(form, name='Form', layer='AGS::FormDiagram')
    scene.update()
    scene.save()
Example #2
0
def RunCommand(is_interactive):

    if 'AGS' not in sc.sticky:
        compas_rhino.display_message('AGS has not been initialised yet.')
        return

    system = sc.sticky['AGS']['system']
    scene = sc.sticky['AGS']['scene']

    filepath = compas_rhino.browse_for_file('Select an input file.',
                                            folder=system['session.dirname'],
                                            filter='obj')
    if not filepath:
        return

    dirname, _ = os.path.split(filepath)
    system['session.dirname'] = dirname

    graph = FormGraph.from_obj(filepath)

    if not graph.is_planar_embedding():
        compas_rhino.display_message(
            'The graph is not planar. Therefore, a form diagram cannot be created.'
        )
        return

    form = FormDiagram.from_graph(graph)

    scene.purge()
    scene.add(form, name='Form', layer='AGS::FormDiagram')
    scene.update()
    scene.save()
Example #3
0
from compas_ags.ags import loadpath

nodes = [[0.0, 0.0, 0], [1.0, 0.0, 0], [2.0, 0.0, 0], [3.0, 0.0, 0],
         [4.0, 0.0, 0], [5.0, 0.0, 0], [6.0, 0.0, 0], [0.0, -1.0, 0],
         [1.0, -1.0, 0], [2.0, -1.0, 0], [3.0, -1.0, 0], [4.0, -1.0, 0],
         [5.0, -1.0, 0], [6.0, -1.0, 0], [1.0, +1.0, 0], [2.0, +1.0, 0],
         [3.0, +1.0, 0], [4.0, +1.0, 0], [5.0, +1.0, 0]]

edges = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (0, 7),
         (1, 8), (2, 9), (3, 10), (4, 11), (5, 12), (6, 13), (0, 14), (14, 15),
         (15, 16), (16, 17), (17, 18), (18, 6), (1, 14), (2, 15), (3, 16),
         (4, 17), (5, 18)]

graph = FormGraph.from_nodes_and_edges(nodes, edges)

form = FormDiagram.from_graph(graph)
force = ForceDiagram.from_formdiagram(form)

index_uv = form.index_uv()

ind = [4, 7, 10, 13, 16]

for index in ind:
    u, v = index_uv[index]
    form.edge_attribute((u, v), 'is_ind', True)
    form.edge_attribute((u, v), 'q', 1.0)

graphstatics.form_update_q_from_qind(form)
graphstatics.force_update_from_form(force, form)

force.vertex_attributes(1, 'xy', [0, 2.5])
Example #4
0
        u = embedding.neighbors(node)[0]
        if u in fixed:
            continue

        a = embedding.node_attributes(u, 'xyz')

        vectors = []
        for v in noleaves.neighbors(u):
            b = embedding.node_attributes(v, 'xyz')
            vectors.append(normalize_vector(subtract_vectors(b, a)))

        ab = scale_vector(
            normalize_vector(
                scale_vector(sum_vectors(vectors), 1 / len(vectors))), length)
        embedding.node_attributes(node, 'xyz', subtract_vectors(a, ab))

# ==============================================================================
# Construct a form diagram of the embedding
# ==============================================================================

form = FormDiagram.from_graph(embedding)

# ==============================================================================
# Visualize the result
# ==============================================================================

plotter = MeshPlotter(form, figsize=(12, 7.5))
plotter.draw_vertices(text='key', radius=0.3)
plotter.draw_edges()
plotter.show()