e1:La^2=(Xa-x)^2+(Ya-y)^2+(Za-z)^2;

e2:Lb^2=(Xb-x)^2+(Yb-y)^2+(Zb-z)^2;

e3:Lc^2=(Xc-x)^2+(Yc-y)^2+(Zc-z)^2;

e4:ratexpand(e1);

e5:ratexpand(e2);

e6:ratexpand(e3);

e7:e5-e4;

e8:e6-e5;

e9:solve([e7,e8],[x,y]);

e10:ratexpand(e9);

e11:factor(e10);

e12:ratsubst(Q,2*(Xb*Yc-Xa*Yc-Xc*Yb+Xa*Yb+Xc*Ya-Xb*Ya),e11);

e12a:coreFa=Xa^2+Ya^2;
e12b:coreFb=Xb^2+Yb^2;
e12c:coreFc=Xc^2+Yc^2;
e12d:coreKa=Lb^2-Lc^2+coreFc-coreFb;
e12e:coreKb=Lc^2-La^2+coreFa-coreFc;
e12f:coreKc=La^2-Lb^2+coreFb-coreFa;
e12g:coreKa+Zc^2-Zb^2=Ka;
e12h:coreKb+Za^2-Zc^2=Kb;
e12i:coreKc+Zb^2-Za^2=Kc;
e12j:subst([e12d,e12e,e12f,e12a,e12b,e12c],e12g);
e12k:subst([e12d,e12e,e12f,e12a,e12b,e12c],e12h);
e12l:subst([e12d,e12e,e12f,e12a,e12b,e12c],e12i);
e12m:subst([reverse(e12j),reverse(e12k),reverse(e12l)],Ka+Kb+Kc);

load("lrats")$
e13:lratsubst(e12j,e12);
e14:lratsubst(e12k,e13);

e15:lratsubst(e12l,e14);

e16:ratsubst(U,(2*Yb-2*Ya)*Zc+(2*Ya-2*Yc)*Zb+(2*Yc-2*Yb)*Za,e15);

e17:ratsubst(R,(2*Xb-2*Xa)*Zc+(2*Xa-2*Xc)*Zb+(2*Xc-2*Xb)*Za,e16);

e18:ratsubst(S,Ka*Ya+Kb*Yb+Kc*Yc,e17);

e19:ratsubst(T,Ka*Xa+Kb*Xb+Kc*Xc, e18);

e19a:subst([reverse(e12j),reverse(e12k),reverse(e12l)],e19);
e20:subst(e19a,e4);

e22:ratsubst(A,Q^2+U^2+R^2,e20);

e23:e22*Q^2;

e24:ratsubst(2*minHalfB,2*Q^2*Za-2*Q*R*Ya+2*Q*U*Xa-2*R*T-2*U*S,e23);

e25:ratsubst(C,(Xa*Q-S)^2+(Ya*Q+T)^2+(Za^2-La^2)*Q^2,e24);

solve(e25,z);