import rhinoscriptsyntax as rs import math # delete everything and start from scratch rs.DeleteObjects(rs.AllObjects()) rs.EnableRedraw(False) # add base point 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 # Return the 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 if radius == 1000: midpoint = add_line_from_polygon(vertices, 1100) # Capture the returned midpoint # add a vertical line to the smallest polygon smallest_polygon_points = polygon_points[100] middle_polygon_points = polygon_points[1000] if len(smallest_polygon_points) > 3 and len(middle_polygon_points) > 3: # 3rd point of the smallest polygon start_point = smallest_polygon_points[9] # 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[9] # 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 tilted_point = ( tilted_point[0] + 770, # move X tilted_point[1], # keep Y tilted_point[2] - 585 # move Z ) # add curve using midpoint rs.AddCurve([end_point, tilted_point, (middle_polygon_points[9][0], middle_polygon_points[9][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[9]) p1_curves = [p1_line1, p1_line2, tilted_line_id] # create petal surface = rs.AddNetworkSrf(p1_curves, continuity=1, edge_tolerance=0, interior_tolerance=0, angle_tolerance=0)