Diff
Not logged in

Differences From Artifact [0f1f35288c2dfafe]:

To Artifact [f037935b3feedc1e]:


1 -typedef long double LD; 2 -typedef complex<LD> CMP; 1 +// Verified: partly by geocon2013 D(1). 3 2 4 -bool line_circle(CMP la, CMP lb, CMP c, LD r, CMP* p1, CMP* p2) 3 +// Crosspoing of a line (not lineseg!) and a circle). 4 +bool line_circle(CMP la, CMP lb, CMP c, double r, CMP* p1, CMP* p2) 5 5 { 6 6 CMP v = (lb-la) / abs(lb-la); 7 7 CMP o = (c-la) / v; 8 8 if( abs(o.imag()) > r ) 9 9 return false; 10 - LD dx = sqrt(r*r - o.imag()*o.imag()); 10 + double dx = sqrt(r*r - o.imag()*o.imag()); 11 11 *p1 = la + (o.real()-dx)*v; 12 12 *p2 = la + (o.real()+dx)*v; 13 13 return true; 14 14 } 15 + 16 +// Whether or not |p| is in the circle (c, r). 17 +bool pt_in_circle(CMP p, CMP c, double r) 18 +{ 19 + return norm(p-c) <= r*r; 20 +} 21 + 22 +// Assuming |o| is outside (C,r), compute the two tangent points. 23 +void sessen(CMP o, CMP c, double r, CMP* p1, CMP* p2) 24 +{ 25 + double len = sqrt(norm(c-o) - r*r); 26 + double theta = asin(r/abs(c-o)); 27 + 28 + if(p1) *p1 = o+(c-o)*polar(len/abs(c-o), theta); 29 + if(p2) *p2 = o+(c-o)*polar(len/abs(c-o), -theta); 30 +} 31 + 32 +// For two points |p| and |q| on (c,r), compute their distance along the circle. 33 +double d_on_c(CMP c, double r, CMP p, CMP q) 34 +{ 35 + return abs(arg((p-c) / (q-c))) * r; 36 +}