(41) Intersection points between circles
12-01-2020, 12:17 AM (This post was last modified: 12-01-2020 12:23 AM by Albert Chan.)
Post: #9
 Albert Chan Senior Member Posts: 1,676 Joined: Jul 2018
RE: Intersection points between circles
(11-30-2020 05:19 PM)rawi Wrote:  alpha = arcsin((y2-y1)/z)
...
We set sg1 = 1 if x2>=x1 and sg1 = -1 if x2<x1
and likewise sg2 = 1 fi y2 >= y1 and sg2 = -1 if y2 < y1.

sx1 = x1 + r1*(cos(alpha+beta))*sg1
sy1 = y1 + r1*(sin(alpha+beta))*sg2
sx2 = x1 + r1*(cos(alpha-beta))*sg1
sy2 = y1 + r1*(sin(alpha-beta))*sg2

If x2 ≥ x1, we have the correct angle. No correction is needed.

If x2 < x1, calculated alpha should really be pi - alpha

cos((pi - alpha) ± beta) = cos(pi - (alpha ∓ beta)) = cos(alpha ∓ beta) * -1
sin((pi - alpha) ± beta) = sin(pi - (alpha ∓ beta)) = sin(alpha ∓ beta)

→ sy does not require correction.

Code:
function intersection(p1,r1, p2, r2)
p2 = p2 - p1        -- p2 relative to p1
local d = p2:abs()
local a = asin(p2:imag()/d)
local b = acos((d*d+(r1+r2)*(r1-r2)) / (2*d*r1))
local sg1 = p2:real()<0 and -1 or 1
return p1 + r1*(cos(a+b)*sg1 + sin(a+b)*I),
p1 + r1*(cos(a-b)*sg1 + sin(a-b)*I)
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)
9.99870384656476+10.101821154325554*I ﻿ ﻿ ﻿ ﻿ ﻿ 6.510943212258768+6.032767080968563*I
lua> intersection(p2,r2,p1,r1)
9.99870384656476+10.101821154325554*I ﻿ ﻿ ﻿ ﻿ ﻿ 6.51094321225877+6.032767080968563*I
 « Next Oldest | Next Newest »

 Messages In This Thread (41) Intersection points between circles - rawi - 11-25-2020, 03:07 PM RE: Intersection points between circles - Albert Chan - 11-25-2020, 06:16 PM RE: Intersection points between circles - rawi - 11-25-2020, 06:48 PM RE: Intersection points between circles - Albert Chan - 11-26-2020, 12:22 AM RE: Intersection points between circles - Albert Chan - 11-30-2020, 02:19 PM RE: Intersection points between circles - rawi - 11-30-2020, 05:19 PM RE: Intersection points between circles - Albert Chan - 11-30-2020, 09:03 PM RE: Intersection points between circles - Albert Chan - 12-01-2020 12:17 AM RE: Intersection points between circles - SlideRule - 11-30-2020, 08:51 PM RE: Intersection points between circles - rawi - 12-01-2020, 09:25 AM RE: Intersection points between circles - Albert Chan - 12-01-2020, 11:59 AM RE: Intersection points between circles - rawi - 12-01-2020, 02:04 PM RE: Intersection points between circles - Albert Chan - 12-10-2020, 01:34 PM

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