import rhinoscriptsyntax as rs import math import Rhino.Geometry as rg from math import * import random as ran rs.EnableRedraw(False) rs.DeleteObjects(rs.AllObjects()) def create_mahanakhon(): ### Parameters spiral_radius = 50 spiral_turns = 3 spiral_height = 200 selection_threshold = 26 # Threshold to delete blocks ### Variables t_area = 150000 # total area of building t_flr = 77 # total floors of building t_height = 314 # total height of building ### average measures pts = [] avg_flr_area = int(t_area / t_flr) avg_flr_height = int(t_height / t_flr) avg_flr_width = max(int(sqrt(avg_flr_area)), 50) # Ensure width is large enough ### pixel dimensions pixel_width = 2 pixel_height = avg_flr_height pixel_depth = 2 ### box_dimensions b_height = 4 b_width = 16 all_boxes = [] ### Terrace Setback setback_h = 2 setback_height = t_flr - b_height # Adjusted to ensure it works setback_width1 = 20 # Increased setback width setback_width2 = 20 # Counters for skipped points skipped_lower_points = 0 skipped_terrace_points = 0 c_pts =[] ### create main building form for x in range(-int(avg_flr_width/2), int(avg_flr_width/2) + pixel_width, pixel_width): ptx = x for y in range(-int(avg_flr_width/2), int(avg_flr_width/2) + pixel_width, pixel_width): pty = y for z in range(0, t_flr): ptz = z * pixel_height + pixel_height / 2 # Remove unnecessary central points if z < setback_height and x in range(-int(avg_flr_width / 2) + b_width, int(avg_flr_width / 2) + pixel_width - b_width) and y in range(-int(avg_flr_width / 2) + b_width, int(avg_flr_width / 2) + pixel_width - b_width): skipped_lower_points += 1 continue center_point = (x, y, ptz) # Center point for the box rs.AddPoint(center_point) # Add the center point to Rhino c_pts.append(center_point) half_size = pixel_height / 2 corner1 = (x - half_size, y - half_size, ptz - half_size) corner2 = (x + half_size, y + half_size, ptz + half_size) my_box = rs.AddBox([ # Add the box to Rhino corner1, (corner2[0], corner1[1], corner1[2]), (corner2[0], corner2[1], corner1[2]), (corner1[0], corner2[1], corner1[2]), (corner1[0], corner1[1], corner2[2]), (corner2[0], corner1[1], corner2[2]), (corner2[0], corner2[1], corner2[2]), (corner1[0], corner2[1], corner2[2]) ]) all_boxes.append(my_box) ### Create the spiral points = [] for t in range(spiral_turns * 360): angle = math.radians(t) x = math.cos(angle) * spiral_radius y = math.sin(angle) * spiral_radius z = (t / 360) * spiral_height points.append((x, y, z)) spiral = rs.AddInterpCurve(points) # Make the pixel structure in the facade for all_box in all_boxes: # Calculate the center point of the block bounding_box = rs.BoundingBox(all_box) center_point = rs.PointAdd(bounding_box[0], rs.VectorDivide(rs.VectorCreate(bounding_box[6], bounding_box[0]), 2)) # Find the closest point on the spiral to the block's center closest_pt = rs.CurveClosestPoint(spiral, center_point) if closest_pt is not None: closest_pt_coords = rs.EvaluateCurve(spiral, closest_pt) distance = rs.Distance(center_point, closest_pt_coords) # Delete the block if it is within the threshold distance if distance < selection_threshold: rs.DeleteObject(all_box) # Run the script create_mahanakhon() rs.EnableRedraw(True)