import rhinoscriptsyntax as rs import math def create_spiral_tower(base_radius, height, num_floors, floor_reduction, spiral_width): """ Args: base_radius (float): Radius of the tower base. height (float): Total height of the tower. num_floors (int): Number of floors. floor_reduction (float): Reduction in radius per floor. spiral_width (float): Width of the spiral wrapping around the tower. """ floor_height = height / num_floors # Calculate floor height floor_curves = [] spiral_points = [] for floor in range(num_floors + 1): # Calculate the radius and height of the current floor current_radius = max(base_radius - (floor * floor_reduction), 0.1) # Avoid negative radius current_height = floor * floor_height # Create a circle for each floor level circle = rs.AddCircle((0, 0, current_height), current_radius) floor_curves.append(circle) # Generate points for the spiral curve angle = floor * (360 / num_floors) # Spiral wraps around the tower x = (current_radius - spiral_width) * math.cos(math.radians(angle)) y = (current_radius - spiral_width) * math.sin(math.radians(angle)) spiral_points.append((x, y, current_height)) # Create the spiral curve rotating with the tower spiral_curve = rs.AddInterpCurve(spiral_points) # Loft the circles to create the main volume if len(floor_curves) > 1: lofted_surfaces = rs.AddLoftSrf(floor_curves) if lofted_surfaces: loft = lofted_surfaces[0] # Extract the main surface # Add a base structure (e.g., a square platform) base_height = -10.0 # Extend the base below the ground level base_points = [ (-base_radius * 1.2, -base_radius * 1.2, base_height), (base_radius * 1.2, -base_radius * 1.2, base_height), (base_radius * 1.2, base_radius * 1.2, base_height), (-base_radius * 1.2, base_radius * 1.2, base_height), ] base_curve = rs.AddPolyline(base_points + [base_points[0]]) base_surface = rs.AddPlanarSrf(base_curve) # Join the base and lofted surfaces into a solid if possible if lofted_surfaces and base_surface: solid = rs.JoinSurfaces([loft] + base_surface, True) if solid: rs.CapPlanarHoles(solid) # Add the spiral as a sweeping feature if spiral_curve: spiral_sweep = rs.AddPipe(spiral_curve, [0, 1], [2.0, 2.0], cap=1) # Parameters for the spiral tower base_radius = 50.0 # Base radius of the tower height = 300.0 # Total height of the tower num_floors = 20 # Number of floors floor_reduction = 3.0 # Radius reduction per floor spiral_width = 5.0 # Width of the spiral wrapping around the tower # Call the function to create the spiral tower create_spiral_tower(base_radius, height, num_floors, floor_reduction, spiral_width)