int getTangents(circle A, circle B, Point*a, Point *b){
int cnt = 0;
if(A.r < B.r) return getTangents(B, A, b, a);
db d2 = (A.p-B.p).len2();
db rdiff = A.r - B.r;
db rsum = A.r + B.r;
if(d2 < rdiff * rdiff) return 0;
Vector AB = B.p - A.p;
db base = atan2(AB.y, AB.x);
if(d2 == 0 && A.r == B.r) return -1;
if(d2 == rdiff * rdiff){
a[cnt] = A.point(base);
b[cnt] = B.point(base);cnt++;
return 1;
}
db ang = acos((A.r - B.r) / sqrt(d2));
a[cnt] = A.point(base+ang); b[cnt] = B.point(base+ang); cnt++;
a[cnt] = A.point(base-ang); b[cnt] = B.point(base-ang); cnt++;
if(d2 == rsum * rsum){
a[cnt] = A.point(base); b[cnt] = B.point(pi+base); cnt++;
}
else if(d2 > rsum * rsum){
db ang = acos((A.r + B.r) / sqrt(d2));
a[cnt] = A.point(base + ang); b[cnt] = B.point(pi+base+ang);cnt++;
a[cnt] = A.point(base - ang); b[cnt] = B.point(pi+base-ang);cnt++;
}
return cnt;
}
转载请注明原文地址:https://blackberry.8miu.com/read-33802.html