0

I am creating a radar for loud sounds, which aims to monitor the production of noise that may be harmful to specific regions of a city. To carry out this project, I developed an arduino prototype, which has three microphones and a camera. Basically, my program would have to do a triangulation, based on the data delivered by the microphones, so that we could identify the source of the sound. This is where the program for calculating the intersection of three circles would come in.

The position of each of the circles would be given from the positioning of the microphones, and the radius would be given from the difference in time that each microphone took to identify the loud noise. After receiving this data, the values in seconds would be transformed into meters through a simple conversion.

The biggest problem with this project is that the first microphone that identifies the noise will have a time difference of 0 seconds, as this would be the reference for the other microphones.

To solve this problem, the function developed by rebrid and improved by Jacques Gaudin (In python how to get intersection point of three or more circles with or without error) would run in a while loop while the ans.success variable is equal to False, while the loop will add 0.01m to the radius of each circumference so that at some point it is found a valid solution to the problem. Having said that my code looked like this:

import matplotlib.pyplot as plt
from scipy.optimize import least_squares

def intersectionPoint(p1,p2,p3):

    x1, y1, dist_1 = (p1[0], p1[1], p1[2])
    x2, y2, dist_2 = (p2[0], p2[1], p2[2])
    x3, y3, dist_3 = (p3[0], p3[1], p3[2])

    def eq(g):
        x, y = g

        return (
            (x - x1)**2 + (y - y1)**2 - dist_1**2,
            (x - x2)**2 + (y - y2)**2 - dist_2**2,
            (x - x3)**2 + (y - y3)**2 - dist_3**2)

    guess = (x1, y1 + dist_1)

    ans = least_squares(eq, guess, ftol=None, xtol=None)

    return ans

def pltC():
    figure, ax = plt.subplots()
    C1 = plt.Circle((ca[0], ca[1]), r1, fill = False)
    C2 = plt.Circle((cb[0], cb[1]), r2, fill = False)
    C3 = plt.Circle((cc[0], cc[1]), r3, fill = False)
    Ci = plt.Circle((ans.x[0], ans.x[1]), 0.1)

    ax.set_aspect(1)
    ax.set_xlim([0, 10])
    ax.set_ylim([0, 10])

    ax.add_artist(C1)
    ax.add_artist(C2)
    ax.add_artist(C3)
    ax.add_artist(Ci)

    plt.title("Exemplo Intersecção de Circluos com o Calculo")
    plt.show()

r1 = 2
r2 = 0
r3 = 4

ca = (0, 0)
cb = (0, 6)
cc = (8, 0)

ans = intersectionPoint((ca[0], ca[1], r1), (cb[0], cb[1], r2), (cc[0], cc[1], r3))

while ans.success == False:
    r1 = round(r1 + 0.01, 2)
    r2 = round(r2 + 0.01, 2)
    r3 = round(r3 + 0.01, 2)

    ca = (0, 0)
    cb = (0, 6)
    cc = (8, 0)
    ans = intersectionPoint((ca[0], ca[1], r1), (cb[0], cb[1], r2), (cc[0], cc[1], r3))

pltC()
print(ans.success)
print(ans.x)
print(r1, r2, r3)

But I'm having a problem as the code is not returning the correct value. It is possible to see in the code that the radius of the first circle (r1) has a value of 2m, r2 has a value of 0m and r3 has a value of 4m.

The correct result with this information would be a point of positions x = 3 and y = 4, where r1 = 5, r2 = 3 and r3 = 7.

But for some reason the program returns us a point with the coordinates x = 2.50377477 and y = 3.74999764, where r1 = 4.45, r2 = 2.45 and r3 = 6.45. Upon drawing these circles, it is clear that the circles do not meet at a single point.

enter image description here

I tried to solve this problem by changing the parameters of the guess variable, but that didn't seem to help

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • Your numbers don't work either. The distance from (0,6) to (3,4) is 3.6, not 3. The distance from (8,0) to (3,4) is 6.4, not 7. What you're really looking for is a weighted average of the 3 points, isn't it? Just have to figure the weighting? – Tim Roberts Mar 30 '23 at 00:28
  • I don't get it at all. Finding the intersection point of 2 circles is as simple as resolving a pythagoras theorem, no? And the third circle will only intersect both if its radius is the exact distance from its center to the previously calculated intersection point of the 2 first? – Rodrigo Rodrigues Mar 30 '23 at 00:33
  • https://mathworld.wolfram.com/Circle-CircleIntersection.html – Rodrigo Rodrigues Mar 30 '23 at 00:39
  • 1
    I also think you are minimizing the wrong function. You are looking for the point that minimizes the distances for a given delta R. What you want to do is find the delta R that comes closest to a 3-way intersection. – Tim Roberts Mar 30 '23 at 00:49
  • Add a .CSV of some example data, please, rounded to 4 places or whatever makes sense. Show us three or four examples of a loud percussive impulse noise being recorded by three microphones at known (x, y) locations. Also, I hope you have calibrated? You know the speed of sound for local temperature / pressure conditions. Place the mics in a straight line at {50, 100, 150} meters from the sound source, and verify the observed delays are consistent with Mach 1. – J_H Mar 30 '23 at 02:09
  • It's also unclear to me. Anyway, why not optimize for three variables (x, y, r_reference), instead of two variables (x, y)? – relent95 Mar 30 '23 at 08:24

0 Answers0