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

Method sample_within

numericals.py:350–371  ·  view source on GitHub ↗
(self, points: list[Point], n: int = 5)

Source from the content-addressed store, hash-verified

348 raise InvalidLineIntersectError()
349
350 def sample_within(self, points: list[Point], n: int = 5) -> list[Point]:
351 center = sum(points, Point(0.0, 0.0)) * (1.0 / len(points))
352 radius = max([p.distance(center) for p in points])
353 if close_enough(center.distance(self.line), radius):
354 center = center.foot(self)
355 a, b = line_circle_intersection(self, Circle(center.foot(self), radius))
356
357 if (a - self.tail).dot(self.head - self.tail) > 0:
358 a, b = self.tail, a
359 else:
360 a, b = self.tail, b # pylint: disable=self-assigning-variable
361
362 result = None
363 best = -1.0
364 for _ in range(n):
365 x = a + (b - a) * unif(0.0, 1.0)
366 mind = min([x.distance(p) for p in points])
367 if mind > best:
368 best = mind
369 result = x
370
371 return [result]
372
373
374def _perpendicular_bisector(p1: Point, p2: Point) -> Line:

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected