def rotate_leaves_for_face_rec(ags_net, gtopt_net, plygn, plyln): """ rotates the leaves of the gtopt_net and adds them to ags_net to facilitate face recognition. """ ags_net_rot=gtopt_net.copy() leaf_pair_dic=leaf_pair_dict(ags_net) for key, pair in leaf_pair_dic.items(): coor_key=ags_net.node_coordinates(pair[0][0]) # the common coordinate if len(pair)>1: # if they are two pairs (sup/load) at one node coor_12=ags_net.node_coordinates(pair[0][1]) coor_22=ags_net.node_coordinates(pair[1][1]) plyln_bln_1=is_point_on_polyline(coor_12, plyln.points, tol=0.1) plyln_bln_2=is_point_on_polyline(coor_22, plyln.points, tol=0.1) if plyln_bln_1 or plyln_bln_2: # the case when one is on polyline if plyln_bln_1: key_g=pair[0][1] key_o=pair[1][1] coor_g=coor_12 coor_o=coor_22 elif plyln_bln_2: key_g=pair[1][1] key_o=pair[0][1] coor_g=coor_22 coor_o=coor_12 add_vec=add_vectors(vector_create(coor_o, coor_key).tolist(), vector_create(coor_g, coor_key).tolist()) add_pt=subtract_vectors(coor_key, add_vec) # bcs the origin is the key_coor ags_net_rot.add_node(key_g, {'x': add_pt[0], 'y': add_pt[1], 'z': add_pt[2]}) ags_net_rot.add_node(key_o, {'x': coor_o[0], 'y': coor_o[1], 'z': coor_o[2]}) ags_net_rot.add_edge(key, key_g) ags_net_rot.add_edge(key, key_o) else: # the case when both are not on polyline ags_net_rot.add_node(pair[0][1], {'x': coor_12[0], 'y': coor_12[1], 'z': coor_12[2]}) ags_net_rot.add_node(pair[1][1], {'x': coor_22[0], 'y': coor_22[1], 'z': coor_22[2]}) ags_net_rot.add_edge(key, pair[0][1]) ags_net_rot.add_edge(key, pair[1][1]) else: # for single leaf coor_12=ags_net.node_coordinates(pair[0][1]) plyln_bln=is_point_on_polyline(coor_12, plyln.points, tol=0.1) if plyln_bln: uv=unit_vector(vector_create(coor_key, coor_12)) if uv[0]-0.0<0.01: # x=0 coor_g=add_vectors(coor_12, (1.0, 0.0, 0.0)) plygn_bln=is_point_in_polygon_xy(coor_g, plygn.points) if plygn_bln: coor_g=add_vectors(coor_12, (-1.0, 0.0, 0.0)) elif uv[1]-0.0<0.01: # y=0 coor_g=add_vectors(coor_12, (0.0, 1.0, 0.0)) plygn_bln=is_point_in_polygon_xy(coor_12, plygn.points) if plygn_bln: coor_g=add_vectors(coor_g, (0.0,-1.0, 0.0)) ags_net_rot.add_node(pair[0][1], {'x': coor_g[0], 'y': coor_g[1], 'z': coor_g[2]}) ags_net_rot.add_edge(key, pair[0][1]) else: # when already in the correct position ags_net_rot.add_node(pair[0][1], {'x': coor_12[0], 'y': coor_12[1], 'z': coor_12[2]}) ags_net_rot.add_edge(key, pair[0][1]) # plot_network(ags_net_rot) return ags_net_rot
def add_vertex_edge_for_load_support(network, sup_dic, load_dic, bars_len, key_removed_dic): """ Post-Processing Function: Adds vertices and edges in accordance with supports and loads returns the cured network """ if not key_removed_dic: load_sup_dic=merge_two_dicts(sup_dic, load_dic) else: load_dic_2=load_dic.copy() for key in key_removed_dic: load_dic_2.pop(key) load_dic_2=merge_two_dicts(load_dic_2, key_removed_dic[key]) load_sup_dic=merge_two_dicts(sup_dic, load_dic_2) # define arbitrary r to be added to get leaf vertex coordinates max_len=max(bars_len) r=max_len/3.0 # make a polygon and polyline from outer vertices of network points = network.to_points() cycles = network_find_cycles(network) mesh = Mesh.from_vertices_and_faces(points, cycles) if 0 in mesh.face and len(mesh.face)>1: mesh.delete_face(0) if len(mesh.face)==1: ver_lis=[key for key in mesh.vertices()] else: ver_lis=mesh.vertices_on_boundary(ordered=True) ver_lis_plyln=ver_lis[:] ver_lis_plyln.append(ver_lis[0]) pt_lis_plygn=[mesh.vertex_coordinates(key) for key in ver_lis] pt_lis_plyln=[mesh.vertex_coordinates(key) for key in ver_lis_plyln] plygn=Polygon(pt_lis_plygn) plyln=Polyline(pt_lis_plyln) # add leaf vertices for key in load_sup_dic: if load_sup_dic[key][0]!=0.0: pt_1=add_vectors(network.node_coordinates(key), (+r, 0.0, 0.0)) plyln_bln=is_point_on_polyline(pt_1, plyln.points, tol=0.001) plygn_bln=is_point_in_polygon_xy(pt_1, plygn.points) if plyln_bln or plygn_bln: pt_1=add_vectors(network.node_coordinates(key), (-r, 0.0, 0.0)) key_2=network.add_node(x=np.asscalar(pt_1[0]), y=pt_1[1], z=0.0) network.add_edge(key, key_2) if load_sup_dic[key][1]!=0.0: pt_2=add_vectors(network.node_coordinates(key), (0.0,+r, 0.0)) plyln_bln=is_point_on_polyline(pt_2, plyln.points, tol=0.001) plygn_bln=is_point_in_polygon_xy(pt_2, plygn.points) if plyln_bln or plygn_bln: pt_2=add_vectors(network.node_coordinates(key), (0.0,-r, 0.0)) key_2=network.add_node(x=pt_2[0], y=np.asscalar(pt_2[1]), z=0.0) network.add_edge(key, key_2) return network, plygn, plyln
def on_polyline(self, polyline): """Determine if the point lies on the given polyline. Parameters ---------- polyline : :class:`compas.geometry.Polyline` or list of points. The polyline. Returns ------- bool True, if the point lies on the polyline. False, otherwise. Examples -------- >>> from compas.geometry import Polyline >>> poly = Polyline([Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0), Point(2.0, 0.0, 0.0)]) >>> point = poly.point(0.5) >>> point.on_polyline(poly) True """ return is_point_on_polyline(self, polyline)