Artifact f037935b3feedc1e1cb4051fc6c5d84565ec6355
// Verified: partly by geocon2013 D(1).
// Crosspoing of a line (not lineseg!) and a circle).
bool line_circle(CMP la, CMP lb, CMP c, double r, CMP* p1, CMP* p2)
{
CMP v = (lb-la) / abs(lb-la);
CMP o = (c-la) / v;
if( abs(o.imag()) > r )
return false;
double dx = sqrt(r*r - o.imag()*o.imag());
*p1 = la + (o.real()-dx)*v;
*p2 = la + (o.real()+dx)*v;
return true;
}
// Whether or not |p| is in the circle (c, r).
bool pt_in_circle(CMP p, CMP c, double r)
{
return norm(p-c) <= r*r;
}
// Assuming |o| is outside (C,r), compute the two tangent points.
void sessen(CMP o, CMP c, double r, CMP* p1, CMP* p2)
{
double len = sqrt(norm(c-o) - r*r);
double theta = asin(r/abs(c-o));
if(p1) *p1 = o+(c-o)*polar(len/abs(c-o), theta);
if(p2) *p2 = o+(c-o)*polar(len/abs(c-o), -theta);
}
// For two points |p| and |q| on (c,r), compute their distance along the circle.
double d_on_c(CMP c, double r, CMP p, CMP q)
{
return abs(arg((p-c) / (q-c))) * r;
}