int insideCircle(point_i p, point_i c, int r) { // all integer version
int dx = p.x - c.x, dy = p.y - c.y;
int Euc = dx * dx + dy * dy, rSq = r * r;
// all integer
return Euc < rSq ? 0 : Euc == rSq ? 1 : 2;
// 0 = inside, 1 = on border, 2 = outside
}
acos(-1.0)
p1
and p2
and radius r
, we can compute the circles:bool circle2PtsRad(point p1, point p2, double r, point &c) {
double d2 = (p1.x - p2.x) * (p1.x - p2.x) +
(p1.y - p2.y) * (p1.y - p2.y);
double det = r * r / d2 - 0.25;
if (det < 0.0) return false;
double h = sqrt(det);
c.x = (p1.x + p2.x) * 0.5 + (p1.y - p2.y) * h;
c.y = (p1.y + p2.y) * 0.5 + (p2.x - p1.x) * h;
return true;
}
double rInCircle(double ab, double bc, double ca) {
return area(ab, bc, ca) / (0.5 * perimeter(ab, bc, ca)); }
double rInCircle(point a, point b, point c) {
return rInCircle(dist(a, b), dist(b, c), dist(c, a)); }
int inCircle(point p1, point p2, point p3, point &ctr, double &r) {
r = rInCircle(p1, p2, p3);
if (fabs(r) < EPS) return 0; // no inCircle center
line l1, l2; // compute these two angle bisectors
double ratio = dist(p1, p2) / dist(p1, p3);
point p = translate(p2, scale(toVec(p2, p3), ratio / (1 + ratio)));
pointsToLine(p1, p, l1);
ratio = dist(p2, p1) / dist(p2, p3);
p = translate(p1, scale(toVec(p1, p3), ratio / (1 + ratio)));
pointsToLine(p2, p, l2);
areIntersect(l1, l2, ctr);
return 1; }
double rCircumCircle(double ab, double bc, double ca) {
return ab * bc * ca / (4.0 * area(ab, bc, ca)); }
double rCircumCircle(point a, point b, point c) {
return rCircumCircle(dist(a, b), dist(b, c), dist(c, a)); }