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

Function circle_circle_intersection

numericals.py:481–504  ·  view source on GitHub ↗

Returns a pair of Points as intersections of c1 and c2.

(c1: Circle, c2: Circle)

Source from the content-addressed store, hash-verified

479
480
481def circle_circle_intersection(c1: Circle, c2: Circle) -> tuple[Point, Point]:
482 """Returns a pair of Points as intersections of c1 and c2."""
483 # circle 1: (x0, y0), radius r0
484 # circle 2: (x1, y1), radius r1
485 x0, y0, r0 = c1.a, c1.b, c1.radius
486 x1, y1, r1 = c2.a, c2.b, c2.radius
487
488 d = math.sqrt((x1 - x0) ** 2 + (y1 - y0) ** 2)
489 if d == 0:
490 raise InvalidQuadSolveError()
491
492 a = (r0**2 - r1**2 + d**2) / (2 * d)
493 h = r0**2 - a**2
494 if h < 0:
495 raise InvalidQuadSolveError()
496 h = np.sqrt(h)
497 x2 = x0 + a * (x1 - x0) / d
498 y2 = y0 + a * (y1 - y0) / d
499 x3 = x2 + h * (y1 - y0) / d
500 y3 = y2 - h * (x1 - x0) / d
501 x4 = x2 - h * (y1 - y0) / d
502 y4 = y2 + h * (x1 - x0) / d
503
504 return Point(x3, y3), Point(x4, y4)
505
506
507class InvalidQuadSolveError(Exception):

Callers 6

intersectMethod · 0.85
intersectMethod · 0.85
naming_positionFunction · 0.85
sketch_tangentFunction · 0.85
sketch_cc_tangentFunction · 0.85
sketch_triangle12Function · 0.85

Calls 2

PointClass · 0.70

Tested by

no test coverage detected