CP Notebook

← all snippets

circumcircle

75mm The circumcirle of a triangle is the circle intersecting all three vertices. ccRadius returns the radius of the circle going through points A, B and C and ccCenter returns the center of the same circle. 15mm

9 lines tested

Needs: "Point.h"

content/geometry/circumcircle.h — Ulf Lundstrom, source: http://en.wikipedia.org/wiki/Circumcircle

typedef Point<double> P;
double ccRadius(P A, P B, P C) {
	return (B-A).dist()*(C-B).dist()*(A-C).dist()/
			abs((B-A).cross(C-A))/2;
}
P ccCenter(P A, P B, P C) {
	P b = C-A, c = B-A;
	return A + (b*c.dist2()-c*b.dist2()).perp()/b.cross(c)/2;
}