Artifact Content
Not logged in

Artifact 0f1f35288c2dfafe8dc2a60c44c65fb22fa3de26


typedef long double LD;
typedef complex<LD> CMP;

bool line_circle(CMP la, CMP lb, CMP c, LD r, CMP* p1, CMP* p2)
{
	CMP v = (lb-la) / abs(lb-la);
	CMP o = (c-la) / v;
	if( abs(o.imag()) > r )
		return false;
	LD dx = sqrt(r*r - o.imag()*o.imag());
	*p1 = la + (o.real()-dx)*v;
	*p2 = la + (o.real()+dx)*v;
	return true;
}