def array_objects(dwg: dict, cols, dx, rows, dy): """ create an array copy of the drawing in cols columns x rows rows spaced dx and dy respectively :parameter cspll: drawing to be arrayed :parameter cols: number of columns to copy to :parameter dx: repeat length for each col :parameter rows: number of rows to copy to :parameter dy: repeat length for each row """ if cols == 0: _dwg_row = dwg.copy() else: _dwg_row = {} for k, layer in dwg.items(): _layer = [] for c in range(0, cols): _layer.extend(translate_layer(layer, (dx * c, 0))) _dwg_row[k] = _layer if rows == 0: return _dwg_row _dwg_rows = {} for k, layer in _dwg_row.items(): _layer = [] for r in range(0, rows): _layer.extend(translate_layer(layer, (0, dy * r))) _dwg_rows[k] = _layer return _dwg_rows
def spherical_segment(l, le, w, we, **faceparamdict): """ lxw mm edge tabbed rectangle, with score for tab folds :parameter l: edge length - untabbed :parameter le: length of end tab :parameter w: side length - sloped tabbed side for spherical triangle_pair :parameter we: length of end tab :parameter faceparamdict: see calling routines :return list of lists [[sublists for sequence of points to be cut],[sublists for sequence of points to be scored]] """ # angles from Coxeter for spherical kaleidoscope # 2,3,3 54deg44min x2, 70deg32min # 2,3,4 35deg16min, 45deg, 54deg44min # 2,3,5 20deg54min, 31deg43min, 37deg23min theta = (35 + 16 / 60) / 2 sint = math.sin(math.radians(theta)) cost = math.cos(math.radians(theta)) # comment out one or other of these lines if ends are to be tabbed or not TODO need to lengthen second straight edge # _edge_dwgl = edgetab_dwg(l, le, **faceparamdict) # normal edge _edge_dwgl = { 'cut': [[(0, 0), (2 * l * sint, 0)]] } # override to give flat edge rather than tab _edge_dwgw = edgetab_dwg(w, we, **faceparamdict) # rect 4 side alternate transform trl = [(180, 2 * l * sint, 0), (270 - theta, 2 * l * sint + w * sint, w * cost), (0, 0, w * cost), (90 + theta, 0, 0)] _dwg = {} for k in _edge_dwgl: _layer = [] for i in range(4): angle, x, y = trl[i] if i % 2 == 0: _layer.extend( translate_layer(rotate_layer(_edge_dwgl[k], angle), (x, y))) else: _layer.extend( translate_layer(rotate_layer(_edge_dwgw[k], angle), (x, y))) _dwg[k] = _layer return _dwg
def triangle_icos(l, le, **faceparamdict): # variation of triangle_pair to give 5 triangles in a row for icosahedron for better fit to A4 size _edge_dwg = edgetab_dwg(l, le, **faceparamdict) _dwg = nsided_polygon(_edge_dwg, l, 3) # icosahedron 5 triangle_pair row for 5r - comment out above line for tetra/octahedron _d = _dwg.copy() _dwg = pair_drawing(_dwg, (180, 0.63 * l, -0.25 * l)) _dwg = pair_drawing(_dwg, (0, 1.35 * l, 0)) for k, layer in _dwg.items(): layer.extend(translate_layer(_d[k], (2.7 * l, 0))) return _dwg
def transformlist_polygon(edge_dwg, trl): """ repeat edge drawing to form a polygon with equal edges from transform list :param edge_dwg: edge drawing :param trl: transform list = list of tuples (angle, x, y) for sequence of translate(rotate(pl, angle), (x,y) operations :return: polygonised drawing """ _dwg = {} for k, layer in edge_dwg.items(): _layer = [] for (angle, x, y) in trl: _layer.extend(translate_layer(rotate_layer(layer, angle), (x, y))) _dwg[k] = _layer return _dwg
def transformlist_polygon_indexedges(edge_dwg_list, trli): """ repeat edge drawing from list of edges to form a polygon with unequal edges from indexed transform list :param edge_dwg_list: list of edge drawings, index position indicated in trli :param trli: transform list = list of tuples (angle, x, y, i) for sequence of translate(rotate(pl, angle), (x,y) operations with index i used to select edge from list of edges :return: polygonised cut and score line point lists """ _dwg = {} for k in edge_dwg_list[0]: _layer = [] for (angle, x, y, i) in trli: _layer.extend( translate_layer(rotate_layer(edge_dwg_list[i][k], angle), (x, y))) _dwg[k] = _layer return _dwg
def triangle_custom_pair(l, le, **faceparamdict): """ l mm edge0 triangle_pair, edge1, edge2 in ratio set below :parameter l: edge length :parameter le: length of end tab :parameter faceparamdict: see calling routines :return [cutlpl, scorelpl] for polyhedron triangle_pair tabbed face """ # 90, 45, 45 triangle_pair # ratio0l for scaling from l, ratio of edge1 and edge2 to edge0 ratio_0l, ratio_10, ratio_20 = 1, 1, math.sqrt(2) # triangle_pair, 3 side transform list l0, le0 = ratio_0l * l, ratio_0l * le trl = [(180, l0, 0), (90, 0, 0), (-45, 0, l0)] # # lengths 1, sqrt2, sqrt3 triangle_pair # # ratio0l for scaling from l, ratio of edge1 and edge2 to edge0 # ratio_0l, ratio_10, ratio_20 = 1, math.sqrt(2), math.sqrt(3) # # triangle_pair, 3 side transform list # # trl = [(180, l, 0), (90, 0, 0), (-54.74, 0, l * ratio_10)] # # mirror # trl = [(0, 0, 0), (90, 0, -l * ratio_10), (-(180 - 54.74), l, 0)] _edge_dwgl = [] _edge_dwgl.append(edgetab_dwg(l0, le0, **faceparamdict)) _edge_dwgl.append( edgetab_dwg(l0 * ratio_10, le0 * ratio_10, **faceparamdict)) _edge_dwgl.append( edgetab_dwg(l0 * ratio_20, le0 * ratio_20, **faceparamdict)) _dwg = {} for k in _edge_dwgl[0]: _layer = [] for i in range(3): angle, x, y = trl[i] _layer.extend( translate_layer(rotate_layer(_edge_dwgl[i][k], angle), (x, y))) _dwg[k] = _layer # pair for easier array tiling _dwg = pair_drawing(_dwg, (180, 1.1 * l0, 1.1 * l0)) return _dwg