def numpy_polar_to_cartesian(ps, coordinates, angles_mode, out_numpy): u_rho, u_phi, u_z = [array(p) for p in ps] if coordinates == 'theta_': if angles_mode == 'degrees': ang1 = radians(u_phi) ang2 = radians(u_z) else: ang1 = u_phi ang2 = u_z rho, phi, theta = numpy_match_long_repeat([u_rho, ang1, ang2]) cartesian = array([ rho * cos(phi) * sin(theta), rho * sin(phi) * sin(theta), rho * cos(theta) ]).T else: if angles_mode == 'degrees': ang1 = radians(u_phi) else: ang1 = u_phi rho, phi, z = numpy_match_long_repeat([u_rho, ang1, u_z]) cartesian = array([rho * cos(phi), rho * sin(phi), z]).T return cartesian if out_numpy else cartesian.tolist()
def numpy_pack_vecs(i0_g, i1_g, i2_g, i3_g, color_mode, use_alpha, output_numpy): series_vec = [] for obj in zip(i0_g, i1_g, i2_g, i3_g): np_obj = [array(p) for p in obj] x, y, z, alpha = numpy_match_long_repeat(np_obj) if color_mode == 'RGB': if use_alpha: vecs = array([x, y, z, alpha]).T else: vecs = array([x, y, z]).T else: if color_mode == 'HSV': convert = hsv_to_rgb else: convert = hsl_to_rgb if use_alpha: vecs = zeros((x.shape[0],4)) vecs[:,:3] = convert(array([x, y, z]).T) vecs[:,3] = alpha else: vecs = convert(array([x, y, z]).T) series_vec.append(vecs if output_numpy else vecs.tolist()) return series_vec
def by_side(verts, direction, percent): np_verts = np.array(verts) np_dir = np.array(direction) np_dir, np_percent = numpy_match_long_repeat([np_dir, np.array(percent)]) values = np_dot(np_verts[:, np.newaxis], np_dir[np.newaxis, :], axis=2) threshold = map_percent(values, np_percent) out_verts_mask = np.any(values >= threshold, axis=1) return out_verts_mask
def numpy_pack_vecs(X_, Y_, Z_, output_numpy): series_vec = [] for obj in zip(X_, Y_, Z_): np_obj = [array(p) for p in obj] x, y, z = numpy_match_long_repeat(np_obj) vecs = array([x, y, z]).T series_vec.append(vecs if output_numpy else vecs.tolist()) return series_vec
def by_normal(vertices, edges, faces, percent, direction): face_normals = pols_normals(vertices, faces, output_numpy=True) np_dir, np_percent = numpy_match_long_repeat( [np.array(direction), np.array(percent)]) values = np_dot(face_normals[:, np.newaxis], np_dir[np.newaxis, :], axis=2) threshold = map_percent(values, np_percent) out_face_mask = np.any(values >= threshold, axis=1) return out_face_mask
def by_normal(vertices, edges, faces, percent, direction): face_normals, _ = calc_mesh_normals(vertices, edges, faces) np_verts = np.array(face_normals) np_dir = np.array(direction) np_dir, np_percent = numpy_match_long_repeat([np_dir, np.array(percent)]) values = np_dot(np_verts[:, np.newaxis], np_dir[np.newaxis, :], axis=2) threshold = map_percent(values, np_percent) out_face_mask = np.any(values >= threshold, axis=1) return out_face_mask
def by_plane(vertices, center, radius, direction): np_verts = np.array(vertices) np_center = np.array(center) np_normal = np.array(direction) normal_length = np.linalg.norm(np_normal, axis=1) np_normal /= normal_length[:, np.newaxis] np_rad = np.array(radius) np_center, np_normal, np_rad = numpy_match_long_repeat( [np_center, np_normal, np_rad]) vs = np_verts[np.newaxis, :, :] - np_center[:, np.newaxis, :] distance = np.abs(np.sum(vs * np_normal[:, np.newaxis, :], axis=2)) out_verts_mask = np.any(distance < np_rad[:, np.newaxis], axis=0) return out_verts_mask
def recurse_fxy_numpy(l1, l2, func, level, out_numpy): if level == 1: nl1 = np.array(l1) nl2 = np.array(l2) nl1, nl2 = numpy_match_long_repeat([nl1, nl2]) res = func(nl1, nl2) if out_numpy else func(nl1, nl2).tolist() return res else: res = [] res_append = res.append # will only be used if lists are of unequal length fl = l2[-1] if len(l1) > len(l2) else l1[-1] for u, v in zip_longest(l1, l2, fillvalue=fl): res_append(recurse_fxy_numpy(u, v, func, level - 1, out_numpy)) return res
def by_edge_dir(vertices, edges, percent, direction): np_verts = np.array(vertices) np_edges = np.array(edges) edges_v = np_verts[np_edges] edges_dir = edges_v[:, 1, :] - edges_v[:, 0, :] np_dir = np.array(direction) np_dir /= np.linalg.norm(np_dir, axis=1)[:, np.newaxis] edges_dir /= np.linalg.norm(edges_dir, axis=1)[:, np.newaxis] np_percent = np.array(percent) np_dir, np_percent = numpy_match_long_repeat([np_dir, np_percent]) values = np.abs( np_dot(edges_dir[:, np.newaxis], np_dir[np.newaxis, :], axis=2)) threshold = map_percent(values, np_percent) out_edges_mask = np.any(values >= threshold, axis=1) return out_edges_mask
def by_cylinder(vertices, center, radius, direction): np_vertices = np.array(vertices) np_location = np.array(center) np_direction = np.array(direction) np_direction = np_direction / np.linalg.norm(np_direction, axis=1)[:, np.newaxis] np_radius = np.array(radius) np_location, np_direction, np_radius = numpy_match_long_repeat( [np_location, np_direction, np_radius]) v_attract = np_vertices[np.newaxis, :, :] - np_location[:, np.newaxis, :] vect_proy = np_dot(v_attract, np_direction[:, np.newaxis, :], axis=2) closest_point = np_location[:, np. newaxis, :] + vect_proy[:, :, np. newaxis] * np_direction[:, np . newaxis, :] dif_v = closest_point - np_vertices[np.newaxis, :, :] dist_attract = np.linalg.norm(dif_v, axis=2) out_verts_mask = np.any(dist_attract < np_radius[:, np.newaxis], axis=0) return out_verts_mask