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 = 45 spiral_turns = 6 spiral_height = 50 ### 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) ### pixel dimensions pixel_width = 5 pixel_height = avg_flr_height pixel_depth = 2 ### box_dimensions b_height = 9 b_width = 16 all_boxes = [] ### Setback setback_height = t_flr - b_height # makes sure the hole in the middle does not go all the way to the top c_pts =[] ### Parameters for the corner cut corner_cut_start_height = int(0.90 * t_flr) # Start of the corner cut (90% height) #corner_cut_width = avg_flr_width # Extend the corner cut to the full building width ### main building form for x in range(-int(avg_flr_width / 2), int(avg_flr_width / 2) + pixel_width, pixel_width): for y in range(-int(avg_flr_width / 2), int(avg_flr_width / 2) + pixel_width, pixel_width): for z in range(0, t_flr): ptz = z * pixel_height + pixel_height / 2 # Remove blocks only in the corner cut region (x-direction) if z >= corner_cut_start_height and x < 0: continue # Skip lower 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): 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) rs.RotateObject(spiral, (0,0,0), 45) spi_points= rs.DivideCurve(spiral, 24) eck_spiral= rs.AddPolyline(spi_points) # Make the pixel structure in the facade for b in all_boxes: pixel_structure = ran.randint(10,15) # Calculate the center point of the box bounding_box = rs.BoundingBox(b) 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 blocks center closest_pt = rs.CurveClosestPoint(eck_spiral, center_point) if closest_pt is not None: closest_pt_coords = rs.EvaluateCurve(eck_spiral, closest_pt) distance = rs.Distance(center_point, closest_pt_coords) # Delete the block if it is within the threshold distance if distance < pixel_structure: rs.DeleteObject(b) #rs.DeleteObject(spiral) #rs.DeleteObject(eck_spiral) # Run the script create_mahanakhon() rs.EnableRedraw(True)