31 lines
745 B
Python
31 lines
745 B
Python
from __future__ import annotations
|
|
|
|
import math
|
|
|
|
|
|
def spiral_positions(n: int, *, max_r: float = 5000.0) -> tuple[list[float], list[float]]:
|
|
"""
|
|
Deterministic "sunflower" (golden-angle) spiral layout.
|
|
|
|
This is intentionally simple and stable across runs:
|
|
- angle increments by the golden angle to avoid radial spokes
|
|
- radius grows with sqrt(i) to keep density roughly uniform over area
|
|
"""
|
|
if n <= 0:
|
|
return ([], [])
|
|
|
|
xs = [0.0] * n
|
|
ys = [0.0] * n
|
|
|
|
golden = math.pi * (3.0 - math.sqrt(5.0))
|
|
denom = float(max(1, n - 1))
|
|
|
|
for i in range(n):
|
|
t = i * golden
|
|
r = math.sqrt(i / denom) * max_r
|
|
xs[i] = r * math.cos(t)
|
|
ys[i] = r * math.sin(t)
|
|
|
|
return xs, ys
|
|
|