Sample a point within the boundary of points.
(self, points: list[Point], n: int = 5)
| 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 | |
| 314 | class InvalidLineIntersectError(Exception): |