円と円の交点の求め方
- 3. 問題のコード
pair<P, P> cc_cross(const C& c1, const C& c2) {
double d = abs(c1.p - c2.p);
double rc = (d*d + c1.r*c1.r - c2.r*c2.r) / (2*d);
double rs = sqrt(c1.r*c1.r - rc*rc);
P diff = (c2.p - c1.p) / d;
return make_pair(c1.p + diff * P(rc, rs),
c1.p + diff * P(rc, -rs));
}
- 5. double rc =
(d*d + c1.r*c1.r - c2.r*c2.r) / (2*d);
cos = a2
+b2
c2
2ab
余弦定理
b
c
aθ
- 6. double rc =
(d*d + c1.r*c1.r - c2.r*c2.r) / (2*d);
b
bcosθ
θ
cos =
a2
+ b2
c2
2ab
b cos =
a2
+ b2
c2
2a
- 8. P diff = (c2.p - c1.p) / d;
=> diffは c1.p→c2.p の単位ベクトル
d
c1.p
c2.p
- 10. diff * P(rc, rs) とは?
=> rc*diff + rs*rot90(diff) のこと
di = (x + jy)
rot90(di ) = rot90(x + jy)
= y + jx
di P(rc, rs) = (x + jy) · (rc + jrs)
= rc(x + jy) + rs( y + jx)
= rcdi + rsrot90(di )