Does anyone know how to make a function like this:
C(p1,p2,p3)=center of circle that goes through p1, p2, and p3?
This is in 2D
Does anyone know how to make a function like this:
C(p1,p2,p3)=center of circle that goes through p1, p2, and p3?
This is in 2D
I have this old converted code stashed away here, but it isn't very good. I don't know how to handle the case where the points are collinear... Perhaps someone can improve on this and make it more Mathematica-y.
circleThrough3Points[{p1_, p2_, p3_}] :=
Module[{ax, ay, bx, by, cx, cy, a, b, c, d, e, f, g, centerx,
centery, r},
{ax, ay} = p1;
{bx, by} = p2;
{cx, cy} = p3;
a = bx - ax;
b = by - ay;
c = cx - ax;
d = cy - ay;
e = a (ax + bx) + b (ay + by);
f = c (ax + cx) + d (ay + cy);
g = 2 (a (cy - by) - b (cx - bx));
If[g == 0, False,
{centerx = (d e - b f)/g,
centery = (a f - c e)/g,
r = Sqrt[(ax - centerx)^2 + (ay - centery)^2]
}];
{centerx, centery, r}]
In action:
Manipulate[
{centerx, centery, radius } = circleThrough3Points[{p1, p2, p3}];
Graphics[
{White,
Rectangle[{-100, -100}, {100, 100}],
Black,
Circle[{centerx, centery}, radius]
}
],
{{p1, {0, 50}}, Locator},
{{p2, {50, 50}}, Locator},
{{p3, {50, 0}}, Locator},
ContentSize -> {250, 250}]

circleThrough3Points[...] := Module[{...}, If[Abs[Normalize[(p2 - p1)].Normalize[(p2 - p3)]] == 1, Inset["Colinear", Scaled[{.5, .5}]], (*your stuff*)Circle[{centerx, centery}, r]]] and just put this in graphics.
– Kuba
Nov 14 '13 at 10:27
FindInstanceand specify that the distance from each point to a point{x,y}should be the same. – C. E. Nov 14 '13 at 06:22Circumsphere[{p1, p2, p3}]- it will help people who land on this page via google search – Jason B. Aug 02 '16 at 16:38