# Does Mathematica have a command that can directly get the center coordinates $(x,y)$ and radius $r$ of a circle?

I have an equation of a circle:

x^2+y^2+2x-15==0


Does Mathematica have a command that can directly get the center coordinates $(x,y)$ and radius $r$?

• you could work with ImplicitRegion and RegionCentroid ... Commented Nov 30, 2016 at 13:06
• @george2079 That's a good one (and 1/(2 Pi) RegionMeasure); I suggest you post this as an answer. Commented Nov 30, 2016 at 13:13
• Indeed, this is what I need. Commented Nov 30, 2016 at 13:18
• A related question. Commented May 24, 2020 at 14:07

c = ImplicitRegion[x^2 + y^2 + 2 x - 15 < 0, {x, y}];
center = RegionCentroid[c]


{-1, 0}

4

Note this does not verify if the input is actually a circle.

• (+1) I would use == instead of < so that no matter what's on the left/right side of the equation it'll work (assuming it's a circle, of course). Commented Nov 30, 2016 at 15:15
• @corey979 RegionCentroid is much slower with the equality for some reason, it does work though. You need to use ArcLength instead of Area to get the radius. Commented Nov 30, 2016 at 15:25
• 1/(2 Pi) RegionMeasure@c then. Just for the record, it's minor details. Commented Nov 30, 2016 at 15:29

No, but you can easily implement your own function:

f[formula_] := {{a, b}, r} /.
Solve[{-2 a == Coefficient[formula, x], -2 b == Coefficient[formula, y],
a^2 + b^2 - r^2 == Last@MonomialList[formula], r > 0}, {a, b, r}][[1]]


so that

eq = x^2 + y^2 + 2 x - 15;

f[eq]


{{-1, 0}, 4}

Method 1:

circleForm = (x - a)^2 + (y - b)^2 - r^2;
sol = SolveAlways[x^2 + y^2 + 2 x - 15 == circleForm, {x, y}];
Pick[sol, NonNegative[r /. sol]]
(*  {{a -> -1, b -> 0, r -> 4}}  *)


As a function:

centerRadius[equation_, {x_, y_}] := Module[{res, a, b, r},
res = SolveAlways[
(equation /. Equal -> Subtract) == (x - a)^2 + (y - b)^2 - r^2,
{x, y}];
(* add check/message if SolveAlways fails, if desired *)
({{a, b}, r} /. Pick[res, NonNegative[r /. res]]) /; res =!= {}
];

centerRadius[x^2 + y^2 + 2 x - 15 == 0, {x, y}]
(*  {{{-1, 0}, 4}}  *)


Method 2: The gradient vanishes at the center; value of form at center is ±1 times the square of the radius, depending on the sign of the coefficients of the quadratic terms.

eqn = x^2 + y^2 + 2 x - 15 == 0;
center = First@Solve[D[eqn, {{x, y}}]]
radius = Sqrt[-(eqn /. Equal -> Subtract /. center)]  (* mult. by -1 * sign(coeff(x^2)) *)
(*
{x -> -1, y -> 0}
4
*)


Circle check (for checking function arguments, if desired):

circleQ[form_, {x_, y_}] := With[{ca = CoefficientArrays[form, {x, y}]},
TrueQ[Length[ca] == 3] &&
MatchQ[Normal@ca[[3]], {{a_, 0}, {0, a_}}]
];

circleQ[x^2 + y^2 + 2 x - 15, {x, y}]
(*  True  *)