Post Reply 
(41) Intersection points between circles
11-30-2020, 09:03 PM
Post: #8
RE: Intersection points between circles
(11-30-2020 05:19 PM)rawi Wrote:  Then we compute the angle between line between midpoints and paralell to x-axis (steps31-38):
alpha = arcsin((y2-y1)/z)

What we wanted is the angle between vector ((x1,y1) to (x2,y2)), and the x-axis.
We should have: -pi ≤ alpha ≤ +pi

Using arcsin, we have -pi/2 ≤ alpha ≤ pi/2. sg1/sg2 correction will not fix this.
Correction should be:

      alpha = arcsin((y2-y1)/z); if x2 < x1 then alpha = pi - alpha end

Or, alpha = arccos((x2-x1)/z); if y2 < y1 then alpha = -alpha end

Code:
function intersection(p1, r1, p2, r2)
    p2 = p2 - p1                    -- p2 relative to p1
    local d, a = p2:abs(), p2:arg() -- polar form
    local b = acos((d*d+(r1+r2)*(r1-r2)) / (2*d*r1))
    return p1 + r1*((a+b)*I):exp(), p1 + r1*((a-b)*I):exp()
end

lua> I = require'complex'.I
lua> p1, r1 = 13+4*I, 6.8
lua> p2, r2 = 6+10*I, 4.0
lua>
lua> intersection(p1,r1, p2,r2)
6.510943212258769+6.032767080968563*I      9.998703846564759+10.101821154325552*I
lua> intersection(p2,r2, p1,r1)
9.99870384656476+10.101821154325554*I      6.51094321225877+6.032767080968563*I

Quote:The difference between your solution and mine is that I use directly the coordinates given. You first transfer it to an easier problem by setting one midpoint to (0;0) and the other to (d;0), but then you have it to transfer back. I am not yet sure which solution is easier.

Your code do the polar form side, mine the rectangular side. Both ways are equivalent.

circles intersections = p1 + r1 * exp((a±b)*I) = p1 + exp(a*I) * (r1*exp(±b*I))

exp(a*I) = (p2-p1) / d
r1*exp(±b*I) = d1 ± h*I
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Intersection points between circles - Albert Chan - 11-30-2020 09:03 PM



User(s) browsing this thread: 1 Guest(s)