Esempio n. 1
0
def process_crossings(network):

    """
    This is the simple version of process_crossing for the case that there is only one crossing
    and to generate planar groundtruss.
    """
    crossings=network_find_crossings(network)  # [(edg1_tup,edg2_tup), (( , ) , ( , )), ...]
    for tup in crossings:
        # find ver coordinates of the two crossing edges
        e_1=network.edge_coordinates(tup[0][0], tup[0][1])
        e_2=network.edge_coordinates(tup[1][0], tup[1][1])
        # find the intersection of the two edges
        xyz=lines_intersection_xy(e_1, e_2)
        # delete the crossing edges
        network.delete_edge(tup[0][0], tup[0][1])
        network.delete_edge(tup[1][0], tup[1][1])
        # add the vertex at intersection
        ver_key=network.add_node(x=xyz[0], y=xyz[1], z=xyz[2])
        # add the four new edges
        network.add_edge(ver_key, tup[0][0])
        network.add_edge(ver_key, tup[0][1])
        network.add_edge(ver_key, tup[1][0])
        network.add_edge(ver_key, tup[1][1])

    return network
Esempio n. 2
0
def network_count_crossings(network):
    """Count the number of crossings (pairs of crossing edges) in the network.

    Parameters
    ----------
    network : Network
        A network object.

    Returns
    -------
    int
        The number of crossings.

    Notes
    -----
    This algorithm assumes that the network lies in the XY plane.

    """
    return len(network_find_crossings(network))
Esempio n. 3
0
if __name__ == '__main__':

    import compas

    from compas.datastructures import Network
    from compas.datastructures import network_is_planar
    from compas.datastructures import network_find_crossings
    from compas.plotters import NetworkPlotter

    network = Network.from_obj(compas.get('lines.obj'))

    network.add_edge(6, 15)

    if not network_is_planar(network):
        crossings = network_find_crossings(network)
    else:
        crossings = []

    print(crossings)

    plotter = NetworkPlotter(network)

    plotter.draw_vertices(radius=0.15,
                          text={key: key
                                for key in network.vertices()})
    plotter.draw_edges(
        color={edge: '#ff0000'
               for edges in crossings for edge in edges})

    plotter.show()