import rhinoscriptsyntax as rs import math def generate_spiral_points(seeds_count, sphere_radius): points = [] phi = math.pi * (3. - math.sqrt(5.)) # golden angle dz = 2.0 / seeds_count # Incremental step for z z = 1.0 - dz / 2.0 # slightly below top of the sphere for i in range(seeds_count): radius_at_z = math.sqrt(1 - z * z) # Radius at z theta = phi * i # Angle x = math.cos(theta) * radius_at_z y = math.sin(theta) * radius_at_z points.append((x * sphere_radius, y * sphere_radius, z * sphere_radius)) # points on sphere z -= dz # Move down the sphere return points def draw_seed(point, sphere_radius, seed_length=1.0, seed_radius=0.5): direction = rs.VectorUnitize(point) end_point = rs.VectorAdd(point, rs.VectorScale(direction, seed_length)) # end point seed line rs.AddLine((0,0,0), end_point) # seed line for i in range(10): # lines in seed head angle = math.pi * i / 10 # Angle increment for j in range(20): # lines around seed head theta = 2 * math.pi * j / 20 # Angle around seed head x = math.sin(angle) * math.cos(theta) * seed_radius y = math.sin(angle) * math.sin(theta) * seed_radius z = math.cos(angle) * seed_radius seed_point = rs.VectorAdd(end_point, (x, y, z)) if rs.Distance((0,0,0), seed_point) > sphere_radius + seed_length: rs.AddLine(end_point, seed_point) def draw_spiral_structure(seeds_count=100, sphere_radius=1): rs.DeleteObjects(rs.AllObjects()) sphere = rs.AddSphere((0, 0, 0), sphere_radius) # main sphere points = generate_spiral_points(seeds_count, sphere_radius) # points on sphere for point in points: # spirale points rs.AddPoint(point) for point in points: # seeds draw_seed(point, sphere_radius) draw_spiral_structure(seeds_count=100, sphere_radius = 3) # dandelion