Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

does anyone know how to make a function

C(p1,p2,p3)=center of circle that goes through p1, p2, and p3?

This is in 2D

Sorry this is poorly written but I desperately need your help

share|improve this question

marked as duplicate by Dr. belisarius, Sjoerd C. de Vries, Yves Klett, Kuba, Artes Nov 14 '13 at 10:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Off topic, of course. See for example… ... or ir you're eager to know more – Dr. belisarius Nov 14 '13 at 2:52
See… -- even though it's 3D, some of the answers can be adapted. – Michael E2 Nov 14 '13 at 2:53
The easiest most brain-dead solution is probably to use FindInstance and specify that the distance from each point to a point {x,y} should be the same. – C. E. Nov 14 '13 at 6:22
up vote 3 down vote accepted

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:

 {centerx, centery, radius } = circleThrough3Points[{p1, p2, p3}];
   Rectangle[{-100, -100}, {100, 100}],
   Circle[{centerx, centery}, radius]
 {{p1, {0, 50}}, Locator},
 {{p2, {50, 50}}, Locator},
 {{p3, {50, 0}}, Locator},
 ContentSize -> {250, 250}]

points and circles

share|improve this answer
Another way is in ClickPane documentation in Applications section. – Kuba Nov 14 '13 at 10:17
To deal with colinear points: 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

Not the answer you're looking for? Browse other questions tagged or ask your own question.