import rhinoscriptsyntax as rs # Clear existing objects rs.DeleteObjects(rs.AllObjects()) def create_london_city_hall(): # Define parameters for the ellipsoid semi_major = 15 # Semi-major axis (X-direction) semi_minor = 15 # Semi-minor axis (Y-direction) vertical_stretch = 29 # Vertical axis (Z-direction) tilt_angle = 30 # Tilt angle in degrees cut_interval = 3 # Cut the ellipsoid every 3 meters # Set the center of the ellipsoid at (0, 0, 0) for proper symmetry center = (0, 0, 0) # The center is now at the middle of the coordinate system # Create a unit sphere at the adjusted center radius = 1 # Initial radius of the sphere sphere = rs.AddSphere(center, radius) if not sphere: print("Failed to create sphere.") return # Scale the sphere to form an ellipsoid # The scaling operation will resize the sphere along each axis to form the ellipsoid rs.ScaleObject(sphere, center, (semi_major, semi_minor, vertical_stretch)) # Rotate the ellipsoid to tilt it rs.RotateObject(sphere, center, tilt_angle, rs.VectorCreate((0, 1, 0), (0, 0, 0))) # Cut the ellipsoid at Z = 0 (equator of the ellipsoid) cutting_plane_1 = rs.AddPlaneSurface(rs.WorldXYPlane(), 50, 50) # A large plane rs.MoveObject(cutting_plane_1, [-25, -25, 0]) # Move the plane to the Z = 0 position # Split the ellipsoid with the plane at Z = 0 split_parts = rs.SplitBrep(sphere, cutting_plane_1) if not split_parts: print("Failed to split the ellipsoid at Z = 0.") return # Clean up the cutting plane rs.DeleteObject(cutting_plane_1) # Now, cut the ellipsoid at intervals of 3 meters along the Z-axis (positive direction) num_slices = int(vertical_stretch / cut_interval) if vertical_stretch % cut_interval != 0: num_slices += 1 # Add one more slice if there is a remainder temp_parts = split_parts # Start with the parts after the first Z = 0 cut for i in range(1, num_slices): # Calculate the Z position for each cut z_cut_position = i * cut_interval # Create a cutting plane at each interval, aligned to the Z-axis # The plane is centered at (0, 0, z_cut_position) so that it intersects with the ellipsoid along X and Y axes cutting_plane = rs.AddPlaneSurface(rs.WorldXYPlane(), 50, 50) # A large plane rs.MoveObject(cutting_plane, [-25, -25, z_cut_position]) # Move the plane to the correct Z position # Split the ellipsoid parts with the plane at the current Z position temp_parts_split = [] for part in temp_parts: split_result = rs.SplitBrep(part, cutting_plane) if split_result: temp_parts_split.extend(split_result) temp_parts = temp_parts_split # Update the list with the new split parts # Cleanup the cutting plane rs.DeleteObject(cutting_plane) # Ensure that all parts are kept and visible in the scene for part in temp_parts: rs.SelectObject(part) print("Simplified London City Hall created with {len(temp_parts)} slices.") # Run the function create_london_city_hall()