import rhinoscriptsyntax as rs import random import math # Parameters sphere_radius = 5.0 cube_size = 10.0 point_count = 1000 # Number of points to generate for volume filling # Define the new sphere center (shifted right and upwards) sphere_center_shift = (10, 10, 10) # Shift by 10 units right (x) and 10 units up (y) # 1. Create the shifted sphere def create_shifted_sphere(): center = (sphere_center_shift[0], sphere_center_shift[1], sphere_center_shift[2]) sphere = rs.AddSphere(center, sphere_radius) return sphere # 2. Create the cube object at the origin def create_cube(): corner1 = (-cube_size/2, -cube_size/2, -cube_size/2) corner2 = (cube_size/2, cube_size/2, cube_size/2) cube = rs.AddBox([corner1, (corner1[0], corner1[1], corner2[2]), (corner1[0], corner2[1], corner1[2]), (corner1[0], corner2[1], corner2[2]), (corner2[0], corner1[1], corner1[2]), (corner2[0], corner1[1], corner2[2]), (corner2[0], corner2[1], corner1[2]), corner2]) return cube # 3. Generate points on the surface of the sphere def generate_sphere_surface_points(resolution): points = [] for i in range(resolution): for j in range(resolution): u = i / float(resolution) * 2 * math.pi v = j / float(resolution) * math.pi x = sphere_radius * math.sin(v) * math.cos(u) + sphere_center_shift[0] y = sphere_radius * math.sin(v) * math.sin(u) + sphere_center_shift[1] z = sphere_radius * math.cos(v) + sphere_center_shift[2] points.append((x, y, z)) return points # 4. Generate points on the surface of the cube def generate_cube_surface_points(resolution): points = [] step = cube_size / resolution half_size = cube_size / 2 # Create points on the six faces of the cube for i in range(resolution): for j in range(resolution): x = -half_size + i * step y = -half_size + j * step # Front and back faces points.append((x, y, half_size)) points.append((x, y, -half_size)) # Left and right faces points.append((half_size, x, y)) points.append((-half_size, x, y)) # Top and bottom faces points.append((x, half_size, y)) points.append((x, -half_size, y)) return points # 5. Connect each point on the sphere with a corresponding point on the cube def connect_points_with_vectors(sphere_points, cube_points): # Ensure both lists have the same number of points min_points = min(len(sphere_points), len(cube_points)) for i in range(min_points): sphere_point = sphere_points[i] cube_point = cube_points[i] # Create a line (vector) between the sphere point and cube point rs.AddLine(sphere_point, cube_point) # Main function to create objects, generate points, and connect them with vectors def main(): # Create shifted sphere and cube at the origin sphere = create_shifted_sphere() cube = create_cube() # Generate surface points for sphere and cube resolution = 20 # Number of divisions for surface points sphere_surface_points = generate_sphere_surface_points(resolution) cube_surface_points = generate_cube_surface_points(resolution) # Add surface points to Rhino scene for pt in sphere_surface_points: rs.AddPoint(pt) for pt in cube_surface_points: rs.AddPoint(pt) # Connect corresponding points with vectors connect_points_with_vectors(sphere_surface_points, cube_surface_points) # Execute the script if __name__ == "__main__": main()