import rhinoscriptsyntax as rs import math # delete everything and start from scratch rs.DeleteObjects(rs.AllObjects()) rs.EnableRedraw(False) # add base point base_p = rs.AddPoint([0, 0, 0]) # create polygon def create_polygon(center, num_sides, radius): if num_sides < 3: print("A polygon must have at least 3 sides.") return None, None # calculate the angles angle_step = 2 * math.pi / num_sides vertices = [] for i in range(num_sides): angle = i * angle_step x = center[0] + radius * math.cos(angle) y = center[1] + radius * math.sin(angle) z = center[2] vertices.append((x, y, z)) # close polygon vertices.append(vertices[0]) # create polygon as polyline polygon_id = rs.AddPolyline(vertices) return polygon_id, vertices def add_line_from_polygon(vertices, line_length): # create sides start_pt = vertices[0] end_pt = vertices[1] # midpoint of the side midpoint = ( (start_pt[0] + end_pt[0]) / 2, (start_pt[1] + end_pt[1]) / 2, (start_pt[2] + end_pt[2]) / 2 ) # add a line from midpoint line_end = (midpoint[0] + line_length, midpoint[1], 0) h_line = rs.AddLine(midpoint, line_end) rs.RotateObject(h_line, midpoint, 20, axis=None, copy=False) return midpoint # parameters for polygons center = [0, 0, 0] num_sides = 9 # radii for polygons radii = [100, 1000, 1400] # list of points of all polygons polygon_points = {} # create polygons for radius in radii: polygon_id, vertices = create_polygon(center, num_sides, radius) if polygon_id: print("Polygon with {} sides and radius {} created successfully!".format(num_sides, radius)) # save vertices polygon_points[radius] = vertices # add the line to the middle polygon midpoint_line_l = 900 if radius == 1000: midpoint = add_line_from_polygon(vertices, midpoint_line_l) # add a vertical line to the smallest polygon smallest_polygon_points = polygon_points[100] middle_polygon_points = polygon_points[1000] largest_polygon_points = polygon_points[1400] if len(smallest_polygon_points) > 3 and len(middle_polygon_points) > 3: # 3rd point of the smallest polygon start_point = smallest_polygon_points[num_sides] # calculate endpoint of vertical line end_point = (start_point[0], start_point[1], start_point[2] + 1500) # add vertical line vertical_line_id = rs.AddLine(start_point, end_point) print("Added a vertical line of 1500 units to the 3rd point of the smallest polygon.") # endpoint for tilted line next_point = middle_polygon_points[num_sides] # add line tilted_line_id = rs.AddLine(end_point, next_point) print("Connected the vertical line's endpoint to the next corner of the middle polygon.") # divide tilted line to get the midpoint tilted_points = rs.DivideCurve(tilted_line_id, 2, create_points=False, return_points=True) if tilted_points: tilted_point = tilted_points[0] rs.DeleteObject(tilted_line_id) # move midpoint to create curve p1_x1 = 770 p1_z1 = 585 tilted_point = ( tilted_point[0] + p1_x1, # move X tilted_point[1], # keep Y tilted_point[2] - p1_z1 # move Z ) # add curve using midpoint curve = rs.AddCurve([end_point, tilted_point, (middle_polygon_points[num_sides][0], middle_polygon_points[num_sides][1], 0)], degree=2) print("Added a control point curve using the modified midpoint of the tilted line.") else: print("Error: Could not divide the tilted line.") # make petal_1 curves p1_line1 = rs.AddLine(end_point, midpoint) p1_line2 = rs.AddLine(midpoint, middle_polygon_points[num_sides]) p1_curves = [p1_line1, p1_line2, curve] # create petal surface = rs.AddNetworkSrf(p1_curves, continuity=1, edge_tolerance=0, interior_tolerance=0, angle_tolerance=0) # mirror and rotate petals to create flower srf_2 = rs.MirrorObject(surface,smallest_polygon_points[num_sides], middle_polygon_points[num_sides],copy=True) for i in range(num_sides): if i>0: rs.RotateObjects((srf_2,surface), base_p, 360/num_sides*i, axis=None, copy=True) # make door curves d1_h1 = 300 d1_ep1 = (midpoint[0], midpoint[1], midpoint[2] + d1_h1) d1_line1 = rs.AddLine(midpoint, d1_ep1) d1_line2 = rs.AddLine(d1_ep1,largest_polygon_points[num_sides]) d1_line3 = rs.AddLine(midpoint,largest_polygon_points[num_sides]) door_curves = [d1_line1, d1_line2, d1_line3] # create door door_1 = rs.AddNetworkSrf(door_curves, continuity=1, edge_tolerance=0, interior_tolerance=0, angle_tolerance=0) # mirror and rotate doors door_2 = rs.MirrorObject(door_1,smallest_polygon_points[num_sides], middle_polygon_points[num_sides],copy=True) for i in range(num_sides): if i>0: rs.RotateObjects((door_1,door_2), base_p, 360/num_sides*i, axis=None, copy=True) """ ph_1 = 500 rs.AddLine(midpoint[2], midpoint[2]+ph_1) p2_h2 = 500 line_end_z = (line_end[0], line_end[1], line_end[2] + p2_h2) rs.AddLine(line_end, line_end_z) """