import rhinoscriptsyntax as rs import math def rotate_point_around_center(point, center, angle): ox, oy, oz = center px, py, pz = point qx = ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy) qy = oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy) qz = pz return (qx, qy, qz) def create_triangular_prism(base_length, height, offset, rotate_angle=0): # Define the 3 points of the triangular base p1 = (0, 0, offset) p2 = (base_length, 0, offset) p3 = (base_length / 2, (base_length * (3 ** 0.5)) / 2, offset) # Calculate the center of the base triangle center = ((p1[0] + p2[0] + p3[0]) / 3, (p1[1] + p2[1] + p3[1]) / 3, offset) # Rotate points if rotate_angle != 0: rotate_angle_rad = math.radians(rotate_angle) p1 = rotate_point_around_center(p1, center, rotate_angle_rad) p2 = rotate_point_around_center(p2, center, rotate_angle_rad) p3 = rotate_point_around_center(p3, center, rotate_angle_rad) # Create the base triangle base = rs.AddPolyline([p1, p2, p3, p1]) # Create the top points p1_top = (p1[0], p1[1], height + offset) p2_top = (p2[0], p2[1], height + offset) p3_top = (p3[0], p3[1], height + offset) # Create the top triangle top = rs.AddPolyline([p1_top, p2_top, p3_top, p1_top]) # Connect the top and bottom triangles rs.AddLine(p1, p1_top) rs.AddLine(p2, p2_top) rs.AddLine(p3, p3_top) # Create the bottom and top planar surfaces bottom_surface = rs.AddPlanarSrf(base)[0] top_surface = rs.AddPlanarSrf(top)[0] # Create the prism by lofting the two triangles (side surfaces) prism = rs.AddLoftSrf([base, top])[0] return prism, bottom_surface, top_surface def create_cylinder(base_length, height): radius = 2.8 # Define the base and top points for the cylinder base_point = (base_length / 2, (base_length * (3 ** 0.5)) / 6, 0) # Center of the triangular base top_point = (base_point[0], base_point[1], height) # Create the cylinder cylinder = rs.AddCylinder(base_point, height, radius) return cylinder def create_hexagonal_prism(side_length, height, offset, center): angle = 60 points = [] for i in range(6): x = center[0] + side_length * math.cos(math.radians(i * angle)) y = center[1] + side_length * math.sin(math.radians(i * angle)) points.append((x, y, offset)) points.append(points[0]) # Create the base base = rs.AddPolyline(points) # Create the top points by adding the height to the offset top_points = [(p[0], p[1], p[2] + height) for p in points] # Create the top top = rs.AddPolyline(top_points) # Connect the top and bottom for i in range(6): rs.AddLine(points[i], top_points[i]) # Create the bottom and top planar surfaces bottom_surface = rs.AddPlanarSrf(base)[0] # Add the bottom surface top_surface = rs.AddPlanarSrf(top)[0] # Add the top surface # Create the prism prism = rs.AddLoftSrf([base, top])[0] # Get the first surface from loft result return prism, bottom_surface, top_surface # Parameters base_length = 10 tri_height = 7 offset = 2.5 # Create the triangular prism prism, bottom_surface, top_surface = create_triangular_prism(base_length, tri_height, offset) # Create the cylinder with height 2.5 starting from the ground cylinder = create_cylinder(base_length, 2.5) # Parameters hex_side_length = base_length / 3 - 0.4 # Side length of the hexagon hex_height = 0.6 # Height of the hexagonal prism hex_offset = tri_height + offset # Offset to place the hexagonal prism on top of the triangular prism # Center point for all objects center_point = (base_length / 2, (base_length * (3 ** 0.5)) / 6, 0) # Create the hexagonal prism on top of the triangular prism hex_prism, hex_bottom_surface, hex_top_surface = create_hexagonal_prism(hex_side_length, hex_height, hex_offset, center_point) # Create the second triangular prism rotated by 180 degrees tri2_height = 7 # Height of the second triangular prism tri2_offset = hex_offset + hex_height # Offset to place the second triangular prism on top of the first hexagonal prism tri_prism_2, bottom_surface_2, top_surface_2 = create_triangular_prism(base_length, tri2_height, tri2_offset, rotate_angle=180) # Create the second hexagonal prism and place it on top of the second triangular prism hex2_height = 0.6 hex2_offset = tri2_offset + tri2_height # Offset to place the second hexagonal prism on top of the second triangular prism hex_prism_2, hex_bottom_surface_2, hex_top_surface_2 = create_hexagonal_prism(hex_side_length, hex2_height, hex2_offset, center_point) tri3_height = 7 # Height of the second triangular prism tri3_offset = hex_offset + hex_height * 2 + 7 # Offset to place the second triangular prism on top of the first hexagonal prism tri_prism_3, bottom_surface_3, top_surface_3 = create_triangular_prism(base_length, tri3_height, tri3_offset, rotate_angle=0)