That site has a good clean solution. The outline of your code would be something like:
def intersects(circle0, circle1):
"""Returns pair of points of intersection, or None if circles are coincident or too far apart."""
P0 = center(circle0)
P1 = center(circle1)
r0 = radius(circle0)
r1 = radius(circle1)
d = distance(P1,P0)
if d > r0 + r1 or d == 0:
return None
compute a = (r0^2 - r1^2 + d^2)/2d
compute P2 = P0 + a(P1 - P0)/d
compute P3a = (x2 + h(y1-y0)/d, y2 - h(x1-x0)/d)
compute P3b = (x2 - h(y1-y0)/d, y2 + h(x1-x0)/d)
return (P3a, P3b)
Let us know how it goes...
Jeff
jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156
"Absolute value", yes. (I keeping waiting for a Vodka advertisement with "Absolut Value" as the tagline :))
||A - B|| means "the distance between A and B" (in math-speak, "the norm of A - B"). If A and B are real numbers, as in this case, then
||A - B|| = abs(A-B). In the general case,
||A - B|| = sqrt((A1-B1)^2 + (A2-B2)^2 + ...), which is a ugly-looking version of the Pythagorean theorem, and collapses to the first formula when A and B have 1 dimension.
It sounds like you're making progress!
Jeff
jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156
Wouldn't it be simpler to create a polygon with coordinates x0,y0 and x,y and x1,y1 back to x0,y0 and fill it with the color to match?
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184