Hi STxAxTIC,
If you check back at reply #3 again you will notice my port of Paul Bourke, actually, I think I tried something else first or very similar from C or C# or C++ and had terrible time with +- confusions of h (the Qwerkey bplus adventure completely gets around that using +- pi/2, aint trig grand? Or as someone else recently said,
Ah, trigonometry! How wonderful.
)
In reply #3 you will notice:
#1 checks to see if an intersect actually exists before going about trying to find the points, this probably by passes problems with imaginary solutions.
#2 also does not once use that gawd-awlful trig-o-metric BS ;-))
My extension of Qwerkey's start was not intended as a completed solution but only as a proof of concept.
By the way bplus: Your solution calculates the cosine of an arc-cosine and could thus be made "simpler", but we're just splitting hairs now.
This?
x1 = r1 * COS(alpha)
Should be this:
x1 = r1 * (r1 ^ 2 + d ^ 2 - r2 ^ 2) / (2 * r1 * d)
x1 = (r1 ^ 2 + d ^ 2 - r2 ^ 2) / (2 * d)
Well OK it does work when substituted in... I think we still have to do SIN calc for l though.
What I don't like about your solution, Mr Static, is that you don't have coordinates for x, y intersects you have offsets that you have to translate back to coordinates of screen your using to use the results. I found that out trying to use your test code to check the Qwerkey bplus solution with same demo code, so your calling it intersect x, y (i1x, i1y) is misdirecting names of variables but maybe splitting hairs again about the way you setup your demos. :)
Update: OK, sorry, works fine in my demo code, so (i1x, i1y) are well named:
SCREEN 12 'intersect2circs test Qwerkey's and b+ derivation 2019-12-12
C1x = 150
C1y = 200
C2x = 300
C2y = 200
r1 = 130
r2 = 100
IntersectTwoCircles C1x, C1y, r1, C2x, C2y, r2, int1x, int1y, int2x, int2y
LINE (int1x
, int1y
)-(int2x
, int2y
), 9
SUB IntersectTwoCircles
(c1x
, c1y
, r1
, c2x
, c2y
, r2
, i1x
, i1y
, i2x
, i2y
) i1x = 0: i1y = 0: i2x = 0: i2y = 0
Dx = c1x - c2x
Dy = c1y - c2y
D2 = Dx ^ 2 + Dy ^ 2
F = (-D2 + r2 ^ 2 - r1 ^ 2) / (2 * r1)
a = Dx / F
b = Dy / F
g = a ^ 2 + b ^ 2
i1x = c1x + r1 * (a + b * h) / g
i1y = c1y + r1 * (b - a * h) / g
i2x = c1x + r1 * (a - b * h) / g
i2y = c1y + r1 * (b + a * h) / g