Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculation of circles
#1
Hello,
I have to solve issue how to calculate intersection of 3 circles. My example is:
1) first cirlce with diameter 10
2) second circle at 0° diameter 7
3) third circle at 120° diamater 12
4) fourth circle at 240° diamater 18

What I need is to find the center of intersection of 3 circles and calculate angle and length - in my example 42° and length 8,5.

Graphical example is here:
https://pasteboard.co/k80ZjARtog9F.jpg

Thanks if you can help me.
Reply
#2
Like 3 lines in the plane don't usually intersect at a single point, 3 circles in the plane don't usually intersect at a single point. So which point(s) do you actually want to calculate? The intersections of pairs of circles?
Reply
#3
For me, the best is calculate center of area of intersections of three circles.
I this solution is too difficult, then I am thinking to calculate intersection of circle 1+2 and 2+3 and 3+1 and then calculate average.
Reply
#4
(Jun-10-2022, 02:15 PM)frohr Wrote: I this solution is too difficult, then I am thinking to calculate intersection of circle 1+2 and 2+3 and 3+1 and then calculate average.
Note that the number of intersection points of a pair of circles can be 0, 1 or 2, or an infinity in the case where they are the same circle.
Reply
#5
I understand. I need it for impeller balancing. There are some regularities and if I can see nice imbalance according fft, I can be pretty sure, there will be intersection like on picture in my first post.
Question is how to make the calculation for the example (picture) from the first post.
Reply
#6
Here is my attempt for the intersection of two circles. It uses geometric inversion in the plane
from math import dist, sqrt

def add(a, b):
    return a[0] + b[0], a[1] + b[1]

def sub(a, b):
    return a[0] - b[0], a[1] - b[1]

def zoom(a, f):
    return a[0] * f, a[1] * f

def intersection(a, b, r1, r2):
    """Return the two intersection points of two circles
    
    Arguments:
        a : a pair of coordinates for the first center
        b : a pair of coordinates for the second center
        r1: the radius of the first circle
        r2: the radius of the second circle
    """
    d = dist(a, b)
    u = zoom(sub(b, a), 1 / d)
    k = sub(a, zoom(u, r1))
    m, n = 1 / (r1 + d - r2), 1 / (r1 + d + r2)
    rr = 0.5 * (n - m)
    tt = 0.5 / r1 - 0.5 * (n + m)
    # raise error if the circles don't intersect
    y = sqrt(rr**2 - tt**2)
    v = -u[1], u[0]
    result = []
    for z in (-y, y):
        w = 0.5 / r1, z
        w = zoom(w, 1 / dist(w, (0,0))**2)
        result.append(add(add(k, zoom(u, w[0])), zoom(v, w[1])))
    return result

def main():
    x = (7, 2)
    a = (3, 1)
    b = (4, 5)
    r1 = dist(a, x)
    r2 = dist(b, x)
    print(intersection(a, b, r1, r2))
    
if __name__ == '__main__':
    main()
Output:
[(7.000000000000001, 2.000000000000001), (-0.058823529411765385, 3.764705882352943)]
Reply
#7
Oh my god, seems a quite complicated for me and it is "only" for 2 circles. Is there any way help me make a function according my example? Any agreement is possible. It is quite important for my app and as I can see I have not enough knowledge. Thanks
Reply
#8
frohr Wrote:Is there any way help me make a function according my example?
The advantage of functions is that you can reuse them. Here is how to add your example to the code
from math import cos, sin, radians

def example2():
    a, r1 = (0, 10), 7
    b, r2 = (10 * cos(radians(-30)), 10 * sin(radians(-30))), 12
    c, r3 = (10 * cos(radians(-150)), 10 * sin(radians(-150))), 18
    print('Intersections between C1 and C2:')
    print(intersection(a, b, r1, r2))
    print('Intersections between C2 and C3:')
    print(intersection(b, c, r2, r3))
    print('Intersections between C1 and C3:')
    print(intersection(a, c, r1, r3))

if __name__ == '__main__':
    example2()
Output:
Intersections between C1 and C2: [(-0.27903833215032314, 3.005563810485458), (6.196878591343983, 6.744436189514549)] Intersections between C2 and C3: [(5.1961524227066285, 6.489125293076062), (5.1961524227066285, -16.48912529307606)] Intersections between C1 and C3: [(-6.390717465839682, 12.85634911588405), (5.66902962935265, 5.893650884115949)]
The results look good to me. It would be a good idea to check that they are correct.
Reply
#9
Hey, thanks, looks great. I am checking it with drawings in autocad and seems it works. I will do more tests. Anyway thanks a lot!
Reply
#10
There is a special case, when r1 + d - r2 == 0, it will fail to compute m, n and raise an exception. Instead of that, it should return [k, k]. This is the case when the first circle is inside the second disk and tangent to the second circle.

You could implement test with Python instead of Autocad. It suffices to check that the intersection points are at distance r1 from the first center and at distance r2 from the second center.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to detect irregular circles in python with opencv johansigaran 4 3,761 May-01-2020, 02:07 AM
Last Post: johansigaran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020