Need help with a problem regarding Descartes' theorem

I'm working on a general Apollonian gasket (i.e., with no particular symmetry). One example might be to populate a Steiner chain with Apollonian circles. I programmed a recursive Descartes' theorem using the equations given in Wikipedia (Descartes' Theorem). I get a nice result for a sample case I set up; it's shown on the left of the figure below.

However, when I tried a test case from another part of the plane a got cockamamie results. To demonstrate this I took the original example, call it $$Z$$, and applied the same algorithm to $$-Z^*$$, i.e., the negative conjugate. The results are seen on the right of the figure below.

I'm trying to determine what's wrong here. Am I making an error? Is the complex Descartes' theorem of limited applicability? I can create a workaround by rotating the working area to the vicinity of the positive $$x$$-axis, but I'm really seeking to develop a robust algorithm.

Any insights or suggestions would be appreciated. • I think debugging your code without seeing the code is impossible. But posting the code here will probably not get you the help you need. I suggest narrowing the problem down by experimenting to see just where in the plane the problem occurs. Then perhaps post instead at stackoverflow.com – Ethan Bolker Nov 18 '18 at 23:45
• Thanks for your reply. It's always nice to know that someone is reading these things. But...Clearly, there's nothing wrong with the code. If it works with one set of circles it should work for all sets. The only inputs are the radii and centers of the circles. And I've tried other set-ups besides the one that's shown. And finally, If I rotate the image on the left by $\pi$, it works correctly – Cye Waldman Nov 19 '18 at 0:02
• There can't be "nothing wrong with the code" if it produces wrong answers some of the time.Students often tell me their programs "should work" even when they fail some of my test cases. (A clock that's stopped is right twice a day.) – Ethan Bolker Nov 19 '18 at 0:06
• Point taken. Didn't mean to sound like an arrogant jerk, but the algorithm is really quite straightforward. You pop in three radii and positions and get one back. – Cye Waldman Nov 19 '18 at 1:43
• No offense. I don't know the formulas you're using, but they might have square roots in them, with ambiguity about sign. I think you have two outputs: new center and new radius.The picture suggests you are getting the radius right all the time. – Ethan Bolker Nov 19 '18 at 1:49