def construct(p0: Point, p1: Point, p2: Point) -> Circle: """Return a circle which passes through the three points.""" try: assert not geometry.colinear(p0, p1, p2) except AssertionError: raise AssertionError( "Circle can not be constructed from three points that are colinear" ) l1 = geometry.perpendicular_bisector(p0, p1) l2 = geometry.perpendicular_bisector(p1, p2) center = l1.intersection(l2) radius = geometry.distance(center, p0) return Circle(center, radius)
def circum_center(self): """Return the circumCenter of the triangle.""" pb_1 = geometry.perpendicular_bisector(self.points[0], self.points[1]) pb_2 = geometry.perpendicular_bisector(self.points[1], self.points[2]) return pb_1.intersection(pb_2)
def test_2(): p1 = Point(3, 0) p2 = Point(5, 0) l = perpendicular_bisector(p1, p2) assert l == Line(1, 0, -4)
def test_3(): p1 = Point(0, 3) p2 = Point(0, 5) l = perpendicular_bisector(p1, p2) assert l == Line(0, 1, -4)
def test_1(): p1 = Point(-3, 0) p2 = Point(0, 3) l = perpendicular_bisector(p1, p2) assert l == Line(1, 1, 0)