MCPcopy Create free account
hub / github.com/google-deepmind/alphageometry / sample_within

Method sample_within

numericals.py:293–311  ·  view source on GitHub ↗

Sample a point within the boundary of points.

(self, points: list[Point], n: int = 5)

Source from the content-addressed store, hash-verified

291 return abs(a * y - b * x) <= ATOM and abs(b * z - c * y) <= ATOM
292
293 def sample_within(self, points: list[Point], n: int = 5) -> list[Point]:
294 """Sample a point within the boundary of points."""
295 center = sum(points, Point(0.0, 0.0)) * (1.0 / len(points))
296 radius = max([p.distance(center) for p in points])
297 if close_enough(center.distance(self), radius):
298 center = center.foot(self)
299 a, b = line_circle_intersection(self, Circle(center.foot(self), radius))
300
301 result = None
302 best = -1.0
303 for _ in range(n):
304 rand = unif(0.0, 1.0)
305 x = a + (b - a) * rand
306 mind = min([x.distance(p) for p in points])
307 if mind > best:
308 best = mind
309 result = x
310
311 return [result]
312
313
314class InvalidLineIntersectError(Exception):

Callers 2

test_sketch_eqangle3Method · 0.45
reduceFunction · 0.45

Calls 6

close_enoughFunction · 0.85
line_circle_intersectionFunction · 0.85
footMethod · 0.80
PointClass · 0.70
CircleClass · 0.70
distanceMethod · 0.45

Tested by 1

test_sketch_eqangle3Method · 0.36