# How can I transform the circle $x^2+y^2+a x+b y+c=0$ into $(x-A)^2+(y-B)^2+C=0$

I want Mathematica to put the circle given by $$x^2+y^2+a x+b y+c=0$$ into the standard form $$(x-A)^2+(y-B)^2+C=0$$, but I haven't been able to.

I tried:

Solve[
CoefficientList[x^2 + y^2 + a x + b y + c = 0, x] ==
CoefficientList[(x - A)^2 + (y - B)^2 + C = 0,
{x, y}]]


but it's wrong and I don't understand why.

• Commented Oct 30, 2020 at 2:14
• Solve[CoefficientList[x^2+y^2+a x+b y+c-((x-A)^2+(y-B)^2+C),{x,y}]==0,{a,b,c}] Commented Oct 30, 2020 at 2:22
• sol = Solve[ First@SolveAlways[(x - A)^2 + (y - B)^2 + C == x^2 + y^2 + a x + b y + c, {y, x}] /. Rule -> Equal, {A, B, C}]  and then (x - A)^2 + (y - B)^2 + C /. First@sol  Commented Oct 30, 2020 at 7:26
• The simplest solution may be: Solve[ForAll[{x, y}, x^2 + y^2 + a x + b y + c == (x - A)^2 + (y - B)^2 + C], {A, B, C}] Commented Oct 31, 2020 at 9:24

Updated

sol = Solve[
Thread[CoefficientList[x^2 + y^2 + a x + b y + c, {x, y}] ==
CoefficientList[(x - A)^2 + (y - B)^2 + C, {x, y}]], {A, B, C}]

(* {{A -> -(a/2), B -> -(b/2), C -> 1/4 (-a^2 - b^2 + 4 c)}} *)

HoldForm[(x - A)^2 + (y - B)^2 + C==0] /. First@sol
% // ReleaseHold


Original

Solve[Thread[
CoefficientList[x^2 + y^2 + a x + b y + c, {x, y}] ==
CoefficientList[(x - A)^2 + (y - B)^2 + C, {x, y}]], {a, b, c}]


{{a -> -2 A, b -> -2 B, c -> A^2 + B^2 + C}}

• @BobHanlon Thanks! Commented Oct 30, 2020 at 2:12

You have the right idea, but go wrong on the details.

rules =
Solve[
CoefficientList[x^2 + y^2 + a x + b y + c, {x, y}] ==
CoefficientList[(x - A)^2 + (y - B)^2 + C, {x, y}],
{A, B, C}]

{{A -> -(a/2), B -> -(b/2), C -> 1/4 (-a^2 - b^2 + 4 c)}}


To show that this is correct transformation:

((x - A)^2 + (y - B)^2 + C == 0 /. rules)[[1]]// Simplify


c + a x + x^2 + b y + y^2 == 0

which is the original equation except that the terms are reordered in the way Mathematica prefers them.

This is a job for SolveAlways, but it does not choose from the desired parameters and the extra parameters just the ones desired. So we use the equivalent Solve[!Eliminate[!eqns,vars]] form, but with the Solve variables specified.

std = r2 + (x - x1)^2 + (y - y1)^2;
Solve[! Eliminate[! (c + a x + x^2 + b y + y^2 == std), {x, y}], {x1, y1, r2}]
std == 0 /. First[%]
(*
{{x1 -> -(a/2), y1 -> -(b/2), r2 -> 1/4 (-a^2 - b^2 + 4 c)}}
1/4 (-a^2 - b^2 + 4 c) + (a/2 + x)^2 + (b/2 + y)^2 == 0
*)