Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
math sin cos solution in Clear category for Searchlights by kdim
def vertices(x, y, l, n):
from math import sin, cos, pi
r = l / 2 / sin(pi / n)
for i in range(n):
yield x + r * sin(2 * pi * i / n), y - r + r * cos(2 * pi * i / n)
def searchlights(polygons, lights):
inlights = lambda vx, vy, x, y, r: (vx - x) ** 2 + (vy - y) ** 2 <= r ** 2 and vx >= 0 <= vy
return sum(any(inlights(*v, *l) for l in lights) for p in polygons for v in vertices(*p))
Feb. 9, 2021
Comments: