MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / intersect

Function intersect

code/geometry/circles.cpp:2–11  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "lines.cpp"
2int intersect(C(A, rA), C(B, rB), point &r1, point &r2) {
3 double d = abs(B - A);
4 if ((rA + rB) < (d - EPS) || d < abs(rA - rB) - EPS)
5 return 0;
6 double a = (rA*rA - rB*rB + d*d) / 2 / d,
7 h = sqrt(rA*rA - a*a);
8 point v = normalize(B - A, a),
9 u = normalize(rotate(B-A), h);
10 r1 = A + v + u, r2 = A + v - u;
11 return 1 + (abs(u) >= EPS); }
12int intersect(L(A, B), C(O, r), point &r1, point &r2) {
13 point H = proj(B-A, O-A) + A; double h = abs(H-O);
14 if (r < h - EPS) return 0;

Callers

nothing calls this directly

Calls 4

sqrtFunction · 0.85
normalizeFunction · 0.85
rotateFunction · 0.85
projFunction · 0.85

Tested by

no test coverage detected