Circle Related Definitions
Circumcircle
PlaneGeometry.circumcircle
— FunctionFunction
circumcircle(points)
Find the circle that goes through a list of points.
Source Code
function circumcircle(points)
ptnum = length(points)
if ptnum <= 2
throw(ArgumentError("At least 3 points are needed, but only $(ptnum) are given."))
end
x, y = @vars x y
c = Point(x, y)
dist = [squaredist(pt, c) for pt in points]
equations = [Eq(dist[i], dist[i+1]) for i in 1:length(points)-1]
sol = solve(equations, [x, y])
center = Point(simplify(sol[x]), simplify(sol[y]))
radius = distance(center, points[1])
radius = simplify(radius)
Circle(center, radius)
end
Picture
A = Point(0,0); B = Point(1, 3); C = Point(4,2)
c = circumcircle([A, B, C])
scatter(shape([A, B, C]), leg=false, color=:red,
series_annotations = text.(["A", "B", "C"], :bottom))
plot!(c, fill=(0, :orange), aspect_ratio=:equal, fillalpha= 0.2)